主题:求解释
#include<stdio.h>
#include<stdlib.h>
typedef struct treenode
{
int data;
struct treenode *l;
struct treenode *r;
}bnode;
void creat (bnode **proot);
void inorder (bnode *bt);
int main()
{
bnode *tree;
tree=(bnode *)malloc(sizeof(bnode));
tree->l=tree->r=NULL;
creat (&tree);
inorder (tree);
}
void creat (bnode **proot)
{bnode *p,*q;
int k;
int i,n;
*proot=NULL;
printf("intput n:");
scanf("%d",&n);
for (i=0;i<n;i++)
{p=(bnode*)malloc(sizeof(bnode));
p->l=NULL;
p->r=NULL;
printf("input k:");
scanf("%d",&k);
p->data=k;
if(*proot==NULL)
*proot=p;
else
{q=*proot;
while(q!=NULL)
{if(q->data=k)
if(q->l!=NULL)
q=q->l;
else
{q->l=p;
q=NULL;
}
if(q->r!=NULL)
q=q->r;
else
{q->r=p;
q=NULL;
}
}
}
}
}
void inorder (bnode *bt)
{
if(bt==NULL)
return;
else
{
if(bt->l!=NULL)
inorder(bt->l);
printf("%d",bt->data);
if(bt->r!=NULL)
inorder(bt->r);
}
}
#include<stdlib.h>
typedef struct treenode
{
int data;
struct treenode *l;
struct treenode *r;
}bnode;
void creat (bnode **proot);
void inorder (bnode *bt);
int main()
{
bnode *tree;
tree=(bnode *)malloc(sizeof(bnode));
tree->l=tree->r=NULL;
creat (&tree);
inorder (tree);
}
void creat (bnode **proot)
{bnode *p,*q;
int k;
int i,n;
*proot=NULL;
printf("intput n:");
scanf("%d",&n);
for (i=0;i<n;i++)
{p=(bnode*)malloc(sizeof(bnode));
p->l=NULL;
p->r=NULL;
printf("input k:");
scanf("%d",&k);
p->data=k;
if(*proot==NULL)
*proot=p;
else
{q=*proot;
while(q!=NULL)
{if(q->data=k)
if(q->l!=NULL)
q=q->l;
else
{q->l=p;
q=NULL;
}
if(q->r!=NULL)
q=q->r;
else
{q->r=p;
q=NULL;
}
}
}
}
}
void inorder (bnode *bt)
{
if(bt==NULL)
return;
else
{
if(bt->l!=NULL)
inorder(bt->l);
printf("%d",bt->data);
if(bt->r!=NULL)
inorder(bt->r);
}
}