境随心转
chinaorg
全部博文(3)
perl(2)
system(1)
2008年(3)
bjchenxu
厚积薄发
分类:
2008-11-24 10:05:41
#!/usr/bin/perl$rootname = "parent";%tree = ("parentleft","child1", "parentright","child2", "child1left","grandchild1", "child1right","grandchild2", "child2left","grandchild3", "child2right","grandchild4", "grandchild3left","gc3child1", "grandchild3right","gc3child2" );$i=@lentree=values(%tree); print ("\n节点数:".($i+1)."\n------------\n"); &print_tree($rootname);sub print_tree{ local ($nodename)=@_; local ($leftchildname,$rightchildname); $leftchildname =$nodename."left"; $rightchildname=$nodename."right"; if ($tree{$leftchildname} ne ""){ $j+=1; &print_tree($tree{$leftchildname}); $j-=1; } # print ("j=$j\n");# print ("k=$k\n");print ((" |")x ($j+$k) );print ( "$nodename\n"); if ($tree{$rightchildname} ne ""){ $k+=1; &print_tree($tree{$rightchildname}); $k-=1; } }
上一篇:DNS 架设过程
下一篇:统计字符出现次数 并排序
登录 注册