void DeleteHeadNode(Node** list, Node* node)
{
if ((node != NULL) && (*list == node)) // check node being deleted
{
Node* next = node->nextnode;
if (next != NULL) // ensure next exists
{
next->prevnode = NULL;
free(*list);
list = &next; // update pointer to head of list
}
else // no next, list is now becoming empty
{
free(*list);
list = NULL; // update pointer to head of list
}
}
}
2 回答
Node**
的用法用作 alias . 如果传递了列表变量的地址,可以通过更改Node*
值来改变它 .通过这种方式,可以将传递的列表变量设置为null或设置为第二个节点 .
以下是使用模式 .
用法:
之前的节点(
prevnode
,双链表)并不是必需的 .while
循环很有意义:别名list
从列表头设置为nextnode字段的地址 . 因此,*list
的后续更改会更改传递的列表变量或某些nextnode字段 .删除头部:
我猜"doesn't work"意味着
list
在你的功能之后不再有效 - 这将是真的 .你应该有