【发布时间】:2020-03-31 21:46:57
【问题描述】:
我正在使用 codeBlock,我正在尝试删除所有零值的节点 起初我删除了头节点,直到头中没有零值 像这样
void exo6(Node* head)
{
Node* p=(Node*)malloc(sizeof(Node));
p=head;
head=p;
if(p->data==0)
{
while(p->data==0)
{
head=p->next;
free(p);
p=head;
}
}
head=p;
然后我继续像这样删除下一个节点
while(p!=null)
{
if(p->next->data==0)
{
Node* q=p->next;
free(p->next);
p->next=q->next;
}else
p=p->next;
}
printf("The NEw list is \n");
display(head);
}
但代码只在头节点上工作
【问题讨论】:
标签: c data-structures struct linked-list singly-linked-list