#include<iostream>
#include<cstdio>
using namespace std;
struct treenode{
int data;
treenode * lchild;
treenode * rchild;
treenode(int c)
:data(c)
,lchild(NULL)
,rchild(NULL)
{}
};
treenode *treeinsert(treenode *root,int x,int father)
{
if(root==NULL)
{
root=new treenode(x);
printf("%d\n",father);
}else if(x <root->data)
{
root->lchild=treeinsert(root->lchild,x,root->data);
}else
{
root->rchild=treeinsert(root->rchild,x,root->data);
}
return root;
}
int main ()
{
int n;
while(scanf("%d",&n)!=EOF)
{
treenode *root=NULL;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
root=treeinsert(root ,x,-1);
}
}
}
二叉排序树
最新推荐文章于 2020-04-12 20:55:08 发布