#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
node *l,*r;
};
int sum;
node *creat(node *root, int x)
{
if(root == NULL)
{
root = new node();
root->l = NULL;
root->r = NULL;
root->data = x;
}
else
{
if(x>root->data)
root->r = creat(root->r,x);
else
root->l = creat(root->l,x);
}
return root;
}
void zhongxu(node *root)
{
if(root == NULL)
return ;
zhongxu(root->l);
if(root)
{
if(sum==0)
{
cout<<root->data;
sum=1;
}
else
cout<<" "<<root->data;
}
zhongxu(root->r);
}
int main()
{
int n;
int x;
while(cin>>n)
{
sum=0;
node *tree = NULL;
while(n--)
{
cin>>x;
tree = creat(tree,x);
}
zhongxu(tree);
cout<<endl;
}
return 0;
}
https://paste.ubuntu.com/p/m8xPTG85WB/
https://paste.ubuntu.com/p/g6cq9gRTMC/