在一个递归方法中使用栈,在每一层递归时,需要栈保持不变,该怎么做啊

解决方案 »

  1.   

    不过好像只要用到方法就要push。
    所以还真难。
      

  2.   


    public static void main(String[] args) {
     String str = "我是共享变量"; runMe(str,0);
    }public static void runMe(String str,int index) {
     if(index < 10) {
      System.out.println(index + "." + str);
      runMe(str,++index);
     }
    }
      

  3.   


    参数传递(参数) {
            if (符合要求)  return
            else {
                     处理参数;
                     参数传递(参数);
            }
    }