📄 tree.cpp
字号:
#include <iostream.h>
#define M 10
#define SN 100
#define QN 100
typedef struct tnode{
char data;
tnode *child[M];
} TNODE;
TNODE *root;
void re_preorder(TNODE *t,int m)
{
int i;
if (t!=NULL)
{
cout<<t->data<<endl;
for (i=0;i<m;i++)
re_preorder(t->child[i],m);
}
}
void st_preorder(TNODE *t,int m)
{
TNODE *s[SN];
int top=0,i;
if (t==NULL)
return;
s[top++]=t;
while (top>0)
{
t=s[--top];
cout<<t->data<<endl;
for (i=m-1;i>=0;i--)
if (t->child[i]!=NULL)
s[top++]=t->child[i];
}
}
void lev_order(TNODE *t,int m)
{
TNODE *q[QN];
TNODE *p;
int head=0,tail=0,i;
q[tail++]=t;
while(head<tail)
{
p=q[head++];
cout<<t->data<<endl;
for (i=0;i<m;i++)
if (p->child[i]!=NULL)
q[tail++]=p->child[i];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -