#include
#include
#include
struct BiTNode//二叉树结点
{
char data;//定义结点
struct BiTNode*lchild;
struct BiTNode*rchild;//定义左右子树指针
}BiTNode,*bitree;
void CreatBinTree(Bitree t) //按先序序列创建二叉树
{
struct BiTNode*t;
char ch;
scanf("%c",&ch);//按先序次序输入二叉树中的结点的值(字符),‘*’表示空树
ch=getchar();
if(ch=='*')//截至符号为*
{
t==NULL;
}
else
{
t=(struct BiTNode*)malloc(sizeof(struct BiTNode));
t->data=ch;
printf("\n 建立左子树\n");
t->lchild=NULL;
t->rchild=NULL;
CreatBinTree( &((*t)->lchild));
printf("\n 建立右子树\n");
CreatBinTree( &((*t)->rchild));
return t;
}
void PreOrder(struct BiTNode *t)
{
if(t!=NULL)
{
printf("%c",t->data);
PreOrder(t->lchild);
PreOrder(t->rchild);
}
}
void MidOrder(struct BiTNode *t)
{
if(t!=NULL)
{
MidOrder(t->lchild);
printf("%c",t->data);
MidOrder(t->rchild);
}
}
void PostOrder(struct BiTNode *t)
{
if(t!=NULL)
{
PostOrder(t->lchild);
PostOrder(t->rchild);
printf("%c",t->data);
}
}
int main()
{
BiTNode Tree;
Create_BinTNode(&Tree);
printf("\n先序遍历\n");
PreOrder_Traverase(Tree);
printf("\n中序遍历\n");
MidOrder_Traverase(Tree);
printf("\n后序遍历\n");
PostOrder_Traverase(Tree);
return 0;
}