#include<iostream>
#include<queue>
using namespace std;
typedef struct tree
{
char data;
tree *lchild;
tree *rchild;
}nod,*nodtree;
void creatTree(nodtree &root)//层次建二叉树
{
nodtree t,work;
queue<nodtree> que;
char ch;
if((ch=getchar())==' ')
root=NULL;
else
{
root=new tree;
root->data=ch;
que.push(root);
while(!que.empty())
{
t=que.front();
if((ch=getchar())==' ')
t->lchild=NULL;
else
{
work=new tree;
work->data=ch;
t->lchild=work;
que.push(work);
}
if((ch=getchar())==' ')
t->rchild=NULL;
else
{
work=new tree;
work->data=ch;
t->rchild=work;
que.push(work);
}
que.pop();
}
}
}
void creatPre(nodtree &root)//先序建二叉树
{
char ch;
if((ch=getchar())==' ')
root=NULL;
else
{
root=new tree;
root->data=ch;
creatPre(root->lchild);
creatPre(root->rchild);
}
}
void preOrder(nodtree r)
{
if(r!=NULL)
{
printf("%c",r->data);
preOrder(r->lchild);
preOrder(r->rchild);
}
}
void inOrder(nodtree root)
{
if(root!=NULL)
{
preOrder(root->lchild);
printf("%c",root->data);
preOrder(root->rchild);
}
}
void enOrder(nodtree root)
{
if(root!=NULL)
{
preOrder(root->lchild);
preOrder(root->rchild);
printf("%c",root->data);
}
}
int main()
{
nodtree root;
creatTree(root);
printf("先序/n");
preOrder(root);
printf("/n");
printf("中序/n");
inOrder(root);
printf("/n");
printf("后序/n");
enOrder(root);
printf("/n");
return 0;
}