#include
#include
#include
#define MAX 100
typedef struct tnode
{
int data;
struct tnode *lchild,*rchild;
}TNODE;
void create();
void insert(int ); /*插入结点*/
void inorder(TNODE *); /*中序遍历*/
TNODE *root=NULL;
void main()
{
clrscr();
create();
inorder(root);
}
void inorder(TNODE *ptr)
{
if(ptr!=NULL)
{
inorder(
ptr->lchild);
printf("%d ",ptr->data);
inorder(ptr->rchild);
}
}
void create()
{
int n,i;
int k[MAX];
printf("please input the node number:");
scanf("%d",&n);
for(i=0;i
for(i=0;i
}
void insert(int m)
{
TNODE *p1,*p2;
if(root==NULL)
{
root=(TNODE *)malloc(sizeof(TNODE));
root->data=m;
root->lchild=root->rchild=NULL;
}
else
{
p1=root;
while(m!=p1->data)
{
if((m
else if((m>p1->data)&&(p1->rchild!=NULL)) p1=p1->rchild;
else if((m
{
p2=(TNODE *)malloc(sizeof(TNODE));
p2->data=m;
p2->lchild=p2->rchild=NULL;
p1->lchild=p2;
return;
}
else if((m>p1->data)&&(p