【发布时间】:2013-12-22 00:08:22
【问题描述】:
我正在尝试使用以下代码从链表中删除一个节点
void deleteMatchNode(node **list, int match)
{
node **temp = list;
node **prev = NULL;
while (*temp != NULL)
{
if ((*temp)->member == match)
{
printf ("match found\n");
break;
}
prev = temp;
temp = &(*temp) ->next;
}
printf("gg1 %p %p\n", *temp, *prev);
(*prev)->next = (*temp)-> next;
printf("gg %p %p\n", *temp, *prev);
printList(*list);
//free(*temp);
}
但是 (*prev)->next 旁边的 (*temp)-> 的赋值正在改变 *temp 的值,请有人指出错误。 printList 按预期工作,但一旦在 *temp 上调用 free,列表就会损坏。
【问题讨论】:
-
请格式化您的代码。
-
temp指向list,所以它们是等价的。如果你在一个中做某事,你就会在另一个中做。
标签: c pointers linked-list