我发现在C语言下面的代码片段,从列表中从C删除链表(指针的指针)
void
remove_ll(struct link_list **head, int key)
{
struct link_list **cur;
for(cur = head; *cur;) {
struct link_list *entry = *cur;
if (entry->key == key) {
*cur = entry->next;
free(entry);
} else {
cur = &entry->next;
}
}
}
我想了解它是如何工作删除的元素。
这是我的想法。
List example:
0x1f7d018 0x1f7d038 0x1f7d078
+++++++++++++++++++ +++++++++++++++++++ +++++++++++++++++++
|0x2174010: | |0x1f7d070: | |0x1f7d090: |
|key = 10 | |key = 34 | |key = 90 |
|&next = 0x1f7d038|++++>|&next = 0x1f7d078|++++>|&next = NULL |
| | | | | |
+++++++++++++++++++ +++++++++++++++++++ +++++++++++++++++++
After deleting the value 34
0x1f7d018 0x1f7d038
+++++++++++++++++++ +++++++++++++++++++
|0x2174010: | |0x1f7d090: |
|key = 10 | |key = 90 |
|&next = 0x1f7d038|++++>|&next = NULL |
| | | |
+++++++++++++++++++ +++++++++++++++++++
这是正确的?
此致敬礼。
运行它,看看。 – kaylum
我已经看到了一些可怕的支架风格,但这一个拿蛋糕。 – EOF