层序遍历:
void levelOrder(struct noderoot)
{
int in, out;
in=out=0;
struct node p[55];
p[in++]=root;
while(in>out)
{
if(p[out])
{
printf("%c",p[out]->data);
p[in++]=p[out]->left;
p[in++]=p[out]->right;
}
out++;
}
}
先序遍历;
void first(struct noderoot)
{
if(root)
{
printf("%c",root->data);
first(root->left);
first(root->right);
}
}
中序遍历:
void mid(treert)
{
if(rt)
{
mid(rt->left);
printf("%c",rt->data);
mid(rt->right);
}
}
后序遍历:
void last(tree*rt)
{
if(rt)
{
last(rt->left);
last(rt->right);
printf("%c",rt->data);
}
}
二叉树-----遍历种类
最新推荐文章于 2024-09-10 21:01:04 发布