递归的代码改成非递归 财富值62

2016-10-24 10:45发布

这里有一段代码,是用递归的形式完成数个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);               }           }        }
付费偷看设置
发送
2条回答
丁丶窦 - 这个人很懒,什么都没留下
1楼 · 2016-10-24 10:54.采纳回答

public static void ndfs(int[] counts){

}
//起码现在看来效果一样啊

一周热门 更多>