#include <iostream>
using namespace std;
struct noot
{
int val;
struct noot *lch;
struct noot *rch;
};
void init (noot *&t)
{
t=(noot *)malloc(sizeof(noot));
t->lch=NULL;
t->rch=NULL;
}
void creat(noot *&t,int a)
{
if(t==NULL)
{
noot *p; init(p);
p->val=a;
t=p;
return;
}
if(a>t->val)
creat(t->rch,a);
if(a<=t->val)
creat(t->lch,a);
return;
}
void dsf(noot *&t)
{
if(t==NULL) return;
dsf(t->lch);
cout<<t->val<<" ";
dsf(t->rch);
return;
}
int main()
{
int n,m;
noot *t;
while(cin>>n)
{
init(t);
for(int i=1;i<=n;i++)
{
cin>>m;
if(i==1)
{
t->val=m;
continue;
}
creat(t,m);
}
dsf(t);
cout<<endl;
}
return 0;
}
er
最新推荐文章于 2024-11-12 19:55:49 发布