📄 demo08_1.cpp
字号:
//Demo08_1
#include "trees.h"
void preorder1(tree t) //对以t为第一棵树的森林的遍历
{
if (t!=NULL){
visite_tnode(t,1); //访问结点
preorder1(t->firstson); //遍历第一棵树的子树森林
preorder1(t->nextbrother); //遍历余下树组成的森林
}
}
void preorder2(tree t) //遍历以t为根的树
{
tree p;
if (t!=NULL){
visite_tnode(t,2); //访问结点
p=t->firstson; //指向第一个孩子结点
while (p!=NULL){
preorder2(p); //遍历以P^为根的子树
p=p->nextbrother; //让P指向t的下一棵子树的根,以便遍历
}
}
}
void main()
{
tree t,p;
load_tree_file(t,"trees\\tree2.tre"); //读入树
display_tree("tree:preorder1",t); //显示
preorder1(t);
printf("\n"); //调用第一个算法
disp_tree("tree:preorder2",t); //重新显示,以清除不必要的内容
p=t; //指示第一棵树的根,以调用第二个算法
while (p!=NULL){
preorder2(p); //调用第二个算法遍历一棵子树
p=p->nextbrother; //指示下一棵树的根,以准备遍历
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -