#include<stdio.h>
#define LEN sizeof(struct tnode)
struct tnode
{
int data;
struct tnode *left,*right;
}ertree;
struct tnode * head,* b,*s;
void insert(struct tnode* b,struct tnode * s)
{
if(b==NULL)
{
b=s;
printf("\nInsert_Start");
}
else if(s->data==b->data)
printf("\nThe data of insert is not suit!");
else if(s->data<b->data)
{
insert(b->left,s);
printf("\nInsert_l");
}
else if(s->data>b->data)
{
insert(b->right,s);
printf("\nInsert_r");
}
}
void creat(struct tnode * b)
{
int x;
struct tnode *s;
b=NULL;
do
{
printf("\nPlease enter the data: ");
scanf("%d",&x);
s=(struct tnode *)malloc(LEN);
s->data=NULL;
s->left=NULL;
s->data=x;
insert(b,s);
printf("\nA_C");
}while(x!=-1);
printf("\nB_C");
/*return(b);*/
printf("\nC_C");
}
void inorder(struct tnode * p)
{
printf("\nThe result is:");
if(p!=NULL)
{
inorder(p->left);
printf("%4d",p->data);
inorder(p->right);
}
}
void main()
{
creat(s);
inorder(s);
getch();
}
|