![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9780f6bec209d5fd8ef219af1cf3c542.png)
#include <bits/stdc++.h>
using namespace std;
int i;
char a[55];
typedef struct Tree
{
char data;
Tree *Lchild;
Tree *Rchild;
}Tree,*BiTree;
BiTree Creat()
{
BiTree root;
char c=a[i++];
if(c==',')
{
root=NULL;
}
else
{
root=(BiTree)malloc(sizeof(BiTree));
root->data=c;
root->Lchild=Creat();
root->Rchild=Creat();
}
return root;
}
void zhong(BiTree root)
{
if(root)
{
zhong(root->Lchild);
cout<<root->data;
zhong(root->Rchild);
}
}
void hou(BiTree root)
{
if(root)
{
hou(root->Lchild);
hou(root->Rchild);
cout<<root->data;
}
}
int main()
{
BiTree root;
while(~scanf("%s",a))
{
i=0;
root=Creat();
zhong(root);
printf("\n");
hou(root);
printf("\n");
}
return 0;
}