先序遍历:在处理儿子的节点之前已经处理了父节点的工作(输出文件的目录结构)
后续遍历:处理父节点在子树节点之前(计算目录大小)
也觉得这个例程不正宗
// 后续排序
static void ListDirTreeAfter(Tree tree, int index)
{
Tree tree_node = tree->FirstChild;
while(tree_node){
//ListDirTree(tree_node, index+1);
printf("%s\n", tree_node->element);
tree_node = tree_node->NextSibling;
}
printf("father is %s\n", tree->element);
if(tree->FirstChild){
ListDirTreeAfter(tree->FirstChild, 0);
}else{
while(tree->NextSibling){
ListDirTreeAfter(tree->NextSibling, 0);
tree = tree->NextSibling;
}
}
printf("\n");
}
输出的结果如下:
usr
aaa(1)
bbb(2)
zhangsan(6)
lisi(7)
lisi1(1)
lisi2(1)
ccc(3)
lisi(1)
ddd(4)
eee(5)
wanger(1)
aaa(1)
bbb(2)
ccc(3)
ddd(4)
eee(5)
father is usr
father is aaa(1)
zhangsan(6)
father is bbb(2)
lisi(7)
father is zhangsan(6)
lisi1(1)
lisi2(1)
father is lisi(7)
father is lisi1(1)
father is lisi2(1)
lisi(1)
father is ccc(3)
father is lisi(1)
father is ddd(4)
wanger(1)
father is eee(5)
father is wanger(1)
wanger(1)
father is eee(5)
father is wanger(1)