码农的空间

codding
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年2月25日

摘要: 打印一个目录的结构,一个目录可以看成一棵树,因此算法的核心是树的遍历,树的遍历又有前序遍历、中序遍历和后序遍历,本文章中使用前序遍历,另外由于树的定义具有递归性质,因此算法采用递归的方式,程序如下:public static void printDirectory(File f,int depth){ if(!f.isDirectory()){//如果不是目录,则打印输出 System.out.println(getTap(depth)+f.getName()); }else{ File[] fs=f.listFiles(); System.out.println(getTap(depth)+ 阅读全文

posted @ 2011-02-25 23:36 我是孙海龙 阅读(4640) 评论(0) 推荐(1) 编辑