求大神指导关于malloc函数的问题
PThrTree addNode(PThrTreeNode p,int i) {//添加儿子
if (p == NULL) {
printf("error!");
return NULL;
}
PThrTreeNode pr=p;
PThrTreeNode q = createThrTreeNode(i);
while (pr != NULL) {
if (q->info < pr->info) {
if (pr->llink == NULL) {
pr->llink = q;
pr = NULL;
}
else pr = pr->llink;
}
else if (q->info > pr->info) {
if (pr->rlink == NULL) {
pr->rlink = q;
pr = NULL;
}
else pr = pr->rlink;
}
}
return p;
}
PThrTreeNode createThrTreeNode(int i) {//创建线索二叉树结点
PThrTreeNode s = (PThrTreeNode)malloc(sizeof(PThrTreeNode));
if (s == NULL) {
printf("创建失败!");
return NULL;
}
s->info = i;
s->llink = NULL;
s->rlink = NULL;
s->ltag = 0;
s->rtag = 0;
return s;
}
addNode函数调用PThrTreeNode函数,目的是为了创建线索二叉树的结点,但是调用的时候前三次都是好的,到了第四次就无法使用了,直接报错说PThrTreeNode s = (PThrTreeNode)malloc(sizeof(PThrTreeNode));触发断点。
然后在一步一步执行的过程中我发现,最后一次创建s这个结点时,在还没有进入函数时s就已经有了内容。想请问下大神们,为什么前几次创建都没问题,第四次就不行了呢。。。感谢!