文章
19
粉丝
0
获赞
168
访问
4.7k
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
struct TNode
{
int data;
TNode *l,*r;
};
void create(TNode*&t,int val,int father)
{
if(t==nullptr)
{
t=new TNode;
t->l=nullptr;
t->r=nullptr;
t->data=val;
cout<<father<<endl;
}
else
{
if(t->data>val)
{
create(t->l,val,t->data);
}
else
{
create(t->r,val,t->data);
}
}
}
int main()
{
int n;
while(cin>>n)
{
int num;
TNode *t=nullptr;
for(int i=0;i<n;i++)
{
cin>>num;
create(t,num,-1);
}
}
}
登录后发布评论
暂无评论,来抢沙发