我正在尝试学习 C,和很多人一样,我对指针有点困惑。无论如何,我创建了一个递归函数来销毁我的链表,但是正如我调试的那样,当我从函数返回时,列表的头部不应该为空,所以我猜这是对指针的一些基本误解。这是函数:
void destroy(struct node *n) {
if (!n) return;
destroy(n->next);
free(n);
n = NULL;
}
void deleteList(struct node** head_ref)
{
struct node* current = *head_ref;
struct node* next;
while (current != NULL) {
next = current->next;
free(current);
current = next;
}
*head_ref = NULL;
}
尝试这样......你可以根据需要更改名称。如果您仍然需要帮助,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)