//根据输入的值顺序不同 树不唯一
//输出前序遍历、中序遍历、后序遍历
#include<stdio.h>
#include<string>
//using namespace std;
struct Node{
Node *lch;
Node *rch;
int c;
}tree[101];
int n;//静态内存中已经分配的节点个数
Node *create(){//申请节点空间并返回其指针
tree[n].lch = tree[n].rch = NULL;
return &tree[n++];
}
//后序遍历
void postOrder(Node* t){
if (t->lch != NULL)
{
postOrder(t->lch);
}
if (t->rch != NULL)
{
postOrder(t->rch);
}
printf("%d", t->c);
}
//前序遍历
void preOrder(Node*t)
{
if (t == NULL)return;
printf("%d", t->c);
if (t->lch != NULL)
preOrder(t->lch);
if (t->rch != NULL)
preOrder(t->rch);
}
//中序遍历
void midOrder(Node*t)
{
if (t->lch != NULL)
midOrder(t->lch);
printf("%d", t->c);
if (t->rch != NULL)
midOrder(t->rch);
}
Node *insert(int num,Node *t){
if (t == NULL)
{
t = create();
t->c = num;
return t;
}
else if (num > t->c)
{
t->rch = insert(num, t->rch);
}
else if (num < t->c)
{
t->lch = insert(num, t->lch);
}
return t;
}
void main()
{
int num;
while (scanf("%d", &num)!=EOF)
{
Node *root=NULL;
n = 0;
for (int i = 0; i < num; i++)
{
int a;
scanf("%d", &a);
root=insert(a, root);
}
preOrder(root);
printf("\n");
midOrder(root);
printf("\n");
postOrder(root);
printf("\n");
}
}