//算法思想:根据输入序列建立二叉排序树,最后用后序遍历输出该二叉树
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
 struct  Node{
    struct Node *lchild;
 struct Node *rchild;
 int c;
}Tree[N];//静态结点N个
int loc=0;
Node *create(){//静态分配一个结点
    Tree[loc].lchild=Tree[loc].rchild=NULL;
 return &Tree[loc++];
}
int count=0;//输入整数数组的下标
Node * bstInsert(Node *T,int key){//二叉排序树的创建,其一定是插在根节点上的
    if(T==NULL){T=create();T->c=key;return T;}
    if(key<T->c){T->lchild=bstInsert(T->lchild,key);}
 if(key>T->c){T->rchild=bstInsert(T->rchild,key);}
 return T;//返回根节点指针
}
void postOrder(Node *T){//后序遍历输出字符串
 if(T->lchild!=NULL)postOrder(T->lchild);
 if(T->rchild!=NULL)postOrder(T->rchild);
      printf("%d ",T->c);
}
int main(){
 int temp[N];
 int i=0;
 scanf("%d",&temp[i]);
    while(temp[i]!=0){
   scanf("%d",&temp[++i]);
 }//输入数据
 Node *T=NULL;
 int count=0;
 while(temp[count]!=0){
 T=bstInsert(T,temp[count++]);
 }
 postOrder(T);
 printf("\n");
return 0;
}