平平庸庸

算法计算树的深度

上一篇 / 下一篇  2013-01-05 15:53:23 / 个人分类:算法

    static int depth=0;
    static int maxdepth=0;
   
    private static void makeDepth(testsuite ts){
        if(ts.getSuitelist().isEmpty()){
            if(depth>maxdepth){
                maxdepth=depth;
            }
        }else{          
            for(testsuite subts:ts.getSuitelist()){
                depth++;
                makeDepth(subts);
                depth--;
            }
        }
    }
 
进入目录加一,退出目录计数减一,到终端节点时计数为此节点深度,比较并设置最大深度。感觉很好!留一笔

TAG: 算法

 

评分:0

我来说两句

Open Toolbar