二叉树的建立和输出问题(急救)
#include"stdio.h"typedef struct node
{ int data[20];
struct node *left,*right;
}ErXTree;
void insert(ErXTree *t,ErXTree *s)
{ if(t==NULL) t=s;
else if(s->data==t->data) return;
else if(s->data<t->data) insert(t->left,s);
else if(s->data>t->data) insert(t->right,s);
}
void creat(ErXTree *t)
{ int x;
ErXTree *s;
t=NULL;
do{ scanf("%d",&x);
s=(ErXTree*)malloc(sizeof(ErXTree));
s->data=x;
s->left=NULL;
s->right=NULL;
insert(t,s);
}while(x!=0);
}
void print(ErXTree *t)
{ if(t!=NULL)
{ printf("%d",t->dada);
if(t->left!=NULL||t->right!=NULL)
{ printf("(");
print(t->left);
if(t->right!=NULL)printf(",");
print(t->right);
printf(")");
}
}
}
main()
{ ErXTree *t;
creat(t);
printf(t);
} 先序二叉数的建立和输出问题,有错误
[此贴子已经被作者于2005-4-1 13:36:42编辑过]