Bnode * btInsert(int x,Bnode *root);
void Inorder(Bnode *root);
void main()
{
int i;
int a[MAX]={60,40,70,20,80};
Bnode * root=NULL;
printf("按关键字序列建立二叉排序树\n");
for(i=0;i<MAX;i++) printf("%d ",a[i]);
printf("\n");
for(i=0;i<MAX;i++) root=btInsert(a[i],root);
printf("中序遍历的二叉排序树\n");
Inorder(root);
printf("\n");
}
Bnode * btInsert(int x,Bnode * root)
{
Bnode *p,*q;
int flag=0;
p=(Bnode *)malloc(sizeof(Bnode));
p->key=x;
p->right=p->left=NULL;
if(root==NULL)
{ root=p; return p; }
q=root;
while(flag==0)
{
if(q->key>x)
{
if(q->left!=NULL)
q=q->left;
else
{
q->left=p;
flag=1;
}
}
else
{
if(q->right!=NULL)
q=q->right;
else
{
4