我正在尝试使用此函数 clearList 清除程序末尾的链接列表,但我不知道该函数的定义究竟有什么问题。
void clearList(struct node *list) {
struct node *p;
for(p = list; p != NULL; p = p->next)
free(p);
}
最佳答案
在释放节点之前,您需要获取next 指针:
p = list; //list is the header
while( p != NULL ){
list = list->next;
free(p);
p = list;
}
关于c - 链表清除函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40944515/