二叉树排序
的有关信息介绍如下:#include
#include
struct node{
int data;
struct node *lc,*rc;
}*head,*s;
//-----必须传递二维指针才能改变实参指针变量的值!!
void find(struct node **p,struct node *x){
if((*p)==NULL)
*p=x;
else if(x->datadata)
find( &((*p)->lc),x);
else
find( &((*p)->rc),x);
}
void print(struct node *p){
if(p!=NULL){
print(p->lc);
printf("%d ",p->data);
print(p->rc);
}
}
int main (){
FILE *fin=fopen("排序二叉树.txt","r");
int a;
while(!feof(fin)){
fscanf(fin,"%d",&a);
s=(struct node *)malloc(sizeof(struct node));//--
s->data=a;
s->lc=s->rc=NULL ;//--
find( &head,s);//--
}
print(head);
fclose(fin);
system("pause");
return 0;
}