打字猴:1.70046831e+09
1700468310 public void addSubordinate(Corp corp){
1700468311
1700468312 this.subordinateList.add(corp);
1700468313
1700468314 }
1700468315
1700468316 //我有哪些下属
1700468317
1700468318 public ArrayList<Corp>getSubordinate(){
1700468319
1700468320 return this.subordinateList;
1700468321
1700468322 }
1700468323
1700468324 }
1700468325
1700468326 场景类中构建树形结构,并进行遍历。组装没有变化,遍历组织机构数稍有变化,如代码清单21-17所示。
1700468327
1700468328 代码清单21-17 稍稍修改的场景类
1700468329
1700468330 public class Client{
1700468331
1700468332 //遍历整棵树,只要给我根节点,我就能遍历出所有的节点
1700468333
1700468334 public static String getTreeInfo(Branch root){
1700468335
1700468336 ArrayList<Corp>subordinateList=root.getSubordinate();
1700468337
1700468338 String info=””;
1700468339
1700468340 for(Corp s:subordinateList){
1700468341
1700468342 if(s instanceof Leaf){//是员工就直接获得信息
1700468343
1700468344 info=info+s.getInfo()+”\n”;
1700468345
1700468346 }else{//是个小头目
1700468347
1700468348 info=info+s.getInfo()+”\n”+getTreeInfo((Branch)s);
1700468349
1700468350 }
1700468351
1700468352 }
1700468353
1700468354 return info;
1700468355
1700468356 }
1700468357
1700468358 }
1700468359
[ 上一页 ]  [ :1.70046831e+09 ]  [ 下一页 ]