private void recursiveInsert(Element ele,ArrayList al) throws Exception{
        String fatherID=(String)ele.getAttributeValue("orgID");
        HashMap hm=new HashMap();
        Element e=null;
        for(int i=0;i<al.size();i++){
            hm=(HashMap)al.get(i);
            String fID=(String)hm.get("fatherID");
           if(fID!=null)
           {
            if(fatherID.equalsIgnoreCase(fID)){
              e=new Element("TreeNode");              if(hm.get("orgID")!=null){//说明是组织机构
                e.setAttribute("orgID",(String)hm.get("orgID"));
                e.setAttribute("ClassType","-1");
                e.setAttribute("Href","seleOrgUser.do?orgID="+(String)hm.get("orgID"));
                e.setAttribute("Title",(String)hm.get("orgName"));
                e.setAttribute("NodeXmlSrc","lkp");
                e.setAttribute("Target","right");
                }
               ele.addContent(e);
               
               recursiveInsert(e,al);
               
             }
             }
            }  //for end
    }如何把上面的方法变成非递归的?谢谢大家了,急,没分请原谅啊 有了以后补上!

解决方案 »

  1.   

    最简单就是把传入的参数移到while(true)外面,剩下的放入里面
      

  2.   

    大概这样子吧import java.util.regex.*;
    public class test{
    public static void f(int i){
    System.out.println(i);
        if(i<0)
          return;
        f(i-1);
    }
    public static void g(int i){
    while(true){
    System.out.println(i);
    if(i<0)
    break;
    i--;
    }
    }
    public static void main(String args[]){
            f(5) ;
            g(8);
    }
    }
      

  3.   

    楼上的好像还是递归吧--> f(i-1);
    问题刚刚解决,是因为数据不太规范,本身id和父id相同,导致溢出。当时我就想到这个问题了,但是以为客户的数据这么多年了,好多人在维护,不会有什么问题,实在走投无路了,就查了下数据,果真发现问题了!还是谢谢各位,以后多多探讨,结贴了!