|
其实还是昨天的那个,很简单,在tc下已经通过了,执行也正常,可是在linux下编译通过,执行后基本正常,但最后最后显示段错误,注意最后,如下:
[code:1]
please you put the data:1
The 1 dian address is: 1074230010 ,the data is 1 ,the lchild is 0 ,the
rchild is 0
please you put the data:2
The 2 dian address is: 1074230030 ,the data is 2 ,the lchild is 0 ,the
rchild is 0
please you put the data:3
The 3 dian address is: 1074230050 ,the data is 3 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:4
The 5 dian address is: 1074230070 ,the data is 4 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:0
please you put the data:5
The 8 dian address is: 1074230110 ,the data is 5 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:0
please you put the data:6
The 11 dian address is: 1074230130 ,the data is 6 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:7
The 13 dian address is: 1074230150 ,the data is 7 ,the lchild is 0 ,the
rchild is 0
please you put the data:8
The 14 dian address is: 1074230170 ,the data is 8 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:0
please you put the data:9
The 17 dian address is: 1074230210 ,the data is 9 ,the lchild is 0 ,the
rchild is 0
please you put the data:0
please you put the data:0
the jiedian adress is 1074230010,data is 1, lchild is 1074230030,rchild is 10742
30130
the jiedian adress is 1074230030,data is 2, lchild is 1074230050,rchild is 1074
230110
the jiedian adress is 1074230050,data is 3, lchild is 0,rchild is 1074230070
the jiedian adress is 1074230070,data is 4, lchild is 0,rchild is 0
the jiedian adress is 1074230110,data is 5, lchild is 0,rchild is 0
the jiedian adress is 1074230130,data is 6, lchild is 0,rchild is 1074230150
the jiedian adress is 1074230150,data is 7, lchild is 1074230170,rchild is 1074
230210
the jiedian adress is 1074230170,data is 8, lchild is 0,rchild is 0
the jiedian adress is 1074230210,data is 9, lchild is 0,rchild is 0
段错误
[/code:1]
到底为什么哪?????
[code:1]
#include <malloc.h>
#include <stdio.h>
typedef struct jied{
struct jied *right;
struct jied *left;
int data;
}Tree;
typedef Tree *pint;
void creat(pint *t,int *num)
{
int dat;
pint x;
*num=*num+1;
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\n",*num,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) return;
if (t->data==0) return;
printf("the jiedian adress is %o,data is %d, lchild is %o,rchild is %o\n ",t,t->data,t->left,t->right);
vis_a(t->left);
vis_a(t->right);
return;
}
void main()
{
pint head;
int *num;
*num=0;
creat(&head,num);
vis_a(head);
}
[/code:1] |
|