|
楼主 |
发表于 2004-6-10 17:40:05
|
显示全部楼层
我刚学数据结构,可能这里有什么闹笑话的地方,不要狠批我啊
typedef struct jied{
struct jied *right;
struct jied *left;
int data;
}Tree;
typedef Tree *pint;
void creat(pint *t,int *num)
{
*num=*num+1;
pint x;
int dat;
printf("please you put the data:");
scanf("%d",dat);
if (dat==0) return;
x=(pint)malloc(sizeof(Tree));
if (!x) printf("malloc error!");
x->data=dat;
x->left=0;
x->right=0;
t=x;
printf(" The %d dian address is: %o ,the data is %d ,the lchild is %o ,the rchild is %o",x,x->data,x->left,x->right);
creat(&x->left,num); /* lchild */
creat(&x->right,num); /* rchild */
return;
}
void vis_a(pint t)
{
if (t->data=0) return;
printf("the jiedian adress is %o,data is %d, lchild is %o,rchild is %o ",t,t->data,t->left,t->right);
vis_a(t->left);
vis_a(t->right);
return;
}
int main()
{
pint head;
int *num;
creat(&head,num);
vis_a(head);
return 0;
} |
|