我想从列表中的给定位置删除节点, 但我的删除功能不起作用。 请帮我一把。从链表中的给定位置删除节点
在此先感谢。
Node* Delete(Node *head, int position)
{
int count=0;
Node* temp, *temp1, *temp2;
temp = head ;
if(head==NULL){
return 0;
}
else if(position == 0)
{
head = head->next;
free(temp);
return head;
}
else{
while(count!= position-1)
{
temp = temp->next;
count++;
}
temp1 = temp->next;
temp->next = temp1->next;
free(temp1);
return temp;
}
return head;
}
*如何*它不工作?你有构建错误吗?崩溃?你有没有试过在调试器中运行?逐行浏览代码以查看它错误的位置? –
请定义所需的行为。回报值应该是多少? – MikeCAT
我的猜测:'return temp;'应该被移除。 – MikeCAT