这里有一段代码,是用递归的形式完成数个for循环的嵌套,麻烦大家帮忙看看如何改写成非递归的代码并且不用写成数个for循环嵌套。
public class Test { static int i=0; public static void main(String[] args) { int[] counts = new int[3]; counts[0] = 1; counts[1] = 2; counts[2] = 3; dfs(counts, 0); } public static void dfs(int[] counts,int index){ for(int i=0;i<counts[index];i++){ if(index == counts.length-1){ System.out.println("hello"); } else{ dfs(counts,index+1); } } }
public static void ndfs(int[] counts){
一周热门 更多>