C. *_*rto 3 c function linked-list
我正在努力学习C,而且和很多人一样,我一直有点困难.无论如何,我做了一个递归函数来销毁我的链表,但是当我调试时,当我从函数返回时,列表的头部不应该是空的,所以我猜它是一些基本的误解指针.这是功能:
void destroy(struct node* n){
if(!n) return;
destroy(n->next);
free(n);
n = NULL; }
Run Code Online (Sandbox Code Playgroud)
提前致谢.
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;
}
Run Code Online (Sandbox Code Playgroud)
尝试这样....你可以根据需要更改名称.如果您仍需要帮助,请告诉我.
| 归档时间: |
|
| 查看次数: |
16130 次 |
| 最近记录: |