懂数据结构的进,帮帮我啊!

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:21:23
懂数据结构的朋友帮我做下这个题,用C语言!顺便可以的话帮我解释一下!谢谢了 做出来再加100分!
建立上颗二叉树,完成它的各种遍历,给出遍历序列!

#include<stdio.h>
#include<stdlib.h>
typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}bitnode,*bitree;//二叉树节点类型和节点指针类型

bitree create_tree() //先序创建二叉树
{
char a;bitree root;
scanf("%c",&a);
fflush(stdin);
if(a=='#')return NULL;//'#'代表空节点
else
{
root=(bitnode *)malloc(sizeof(bitnode));
root->data=a;
root->lchild=create_tree();
root->rchild=create_tree();
}
return root;
}
void layerorder(bitree T)//层次遍历
{
int front=0;int rear=0;
bitree Q[100];//Q足够大
Q[rear++]=T;
while(rear!=front)
{
bitree p;
p=Q[front++];
putchar(p->data);
if(p->lchild)Q[rear++]=p->lchild;
if(p->rchild)Q[rear++]=p->rchild;
}
}
void preorder(bitree roo