【发布时间】:2016-06-01 16:43:31
【问题描述】:
大家好,我做了一个函数,它根据您要从链表中删除的数字递归地从链表中删除。但是在删除之后,如果我尝试打印列表它的堆栈并且存在运行时错误,因为在删除之后没有任何东西代替数字。如何完成代码?
struct node* delete_item(struct node* head, int num)
{
if (head == NULL) { // Found the tail
printf("not found\n");
return NULL;
}
else if (head->data == num)
{ // Found one to delete
head = head->next;
free(head);
printf("num founded");
return head->next;
}
else
{ // Just keep going
head->next = delete_item(head->next, num);
return head;
}
}
【问题讨论】:
标签: c recursion data-structures struct linked-list