【发布时间】:2013-07-09 22:05:57
【问题描述】:
我正在学习 C 中的链表,但我的删除功能有问题。线路出现分段错误:
while(current1 != NULL && (current1->next->data != d))
void delete(int d)
{
struct list * current1 = head;
struct list * current2;
if (len() == 0)
{ //prtError("empty");
exit(0);
}
if (head -> data == d)
{
head = head -> next;
}
//Check if last node contains element
while (current1->next->next != NULL)
current1 = current1->next;
if(current1->next->data == d)
current1->next == NULL;
current1 = head; //move current1 back to front */
while(current1 != NULL && (current1->next->data != d))
current1 = current1 -> next;
current2 = current1 -> next;
current1 -> next = current2 -> next;
}
【问题讨论】:
-
我修复了 NULL bu 的问题,现在我在最后一行 current1 -> next = curren2 -> next 遇到了错误
-
我编辑了我的答案以向您解释现在收到此错误。
标签: c list linked-list fault