我正在使用搜索树,并查看树是否结束,我检查它是否为空。我的问题是当我使用free()时指针值不会变为NULL。
我也尝试过使用指向 free 的指针,然后设置为 NULL,但它没有用。
在这种情况下,我想删除搜索树上的最大数字,但我的打印功能无法识别释放的值,而是打印 0。
typedef struct nodo {
int val;
struct nodo *l, *r;
} *ABin;
void print (ABin a) {
if (a != NULL) {
print (a -> l);
printf(" %d ",a -> val);
print (a -> r);
}
}
ABin remBiggerA (ABin *a) {
ABin b = (*a), aux = b;
int i = 0;
if (b == NULL) i = 1;
while (i == 0) {
if (b -> r == NULL) {
free (b);
i = 1;
}
else b = b -> r;
}
(*a) = aux;
return aux;
}