以下是代码
该函数的功能是根据一个字符串生成一个二叉树,
传入的字符串是该二叉树前序遍历的结果,
'#'代表NULL,
例如:"abd#e##fg###c##".
bintree createbintree(char *s) {
bintree stack[Maxsize];
int top = 0;
bintree t = (bintree)malloc(sizeof(bintnode));
bintree p = t;
while ((*s)!='\0')
{
if ((*s)!='#')
{
p->data = *s;
stack[top++] = p;
p->lchild = (bintree)malloc(sizeof(bintnode));
p = p->lchild;
}
else
{
if(p!=NULL)
free(p);
if (top == 0)return t;
p = stack[--top];
p->rchild = (bintree)malloc(sizeof(bintnode));
p = p->rchild;
}
s++;
}
return t;
}
在第一次遇到#的时候,就是运行到上图所示代码的地方,
在执行完p=stack[--top]后,p的内容是这样的
可是在执行p->rchild = (bintree)malloc(sizeof(bintnode));后
左右孩子的地址空间一样了,这是什么造成的?