打字猴:1.70046781e+09
1700467810
1700467811 salesDep.add(h);
1700467812
1700467813 salesDep.add(i);
1700467814
1700467815 //最后一个财务
1700467816
1700467817 financeDep.add(j);
1700467818
1700467819 //打印写完的树状结构
1700467820
1700467821 System.out.println(ceo.getInfo());
1700467822
1700467823 //打印出来整个树形
1700467824
1700467825 getAllSubordinateInfo(ceo.getSubordinateInfo());
1700467826
1700467827 }
1700467828
1700467829 //遍历所有的树枝节点,打印出信息
1700467830
1700467831 private static void getAllSubordinateInfo(ArrayList subordinateList){
1700467832
1700467833 int length=subordinateList.size();
1700467834
1700467835 //定义一个ArrayList长度,不要在for循环中每次计算
1700467836
1700467837 for(int m=0;m<length;m++){
1700467838
1700467839 Object s=subordinateList.get(m);
1700467840
1700467841 if(s instanceof Leaf){//是个叶子节点,也就是员工
1700467842
1700467843 ILeaf employee=(ILeaf)s;
1700467844
1700467845 System.out.println(((Leaf)s).getInfo());
1700467846
1700467847 }else{
1700467848
1700467849 IBranch branch=(IBranch)s;
1700467850
1700467851 System.out.println(branch.getInfo());
1700467852
1700467853 //再递归调用
1700467854
1700467855 getAllSubordinateInfo(branch.getSubordinateInfo());
1700467856
1700467857 }
1700467858
1700467859 }
[ 上一页 ]  [ :1.70046781e+09 ]  [ 下一页 ]