C语言的链表删除问题

2025-02-28 04:24:36
推荐回答(1个)
回答1:

你的while的大括号搞错地方了

struct student *DeleteLinkList(struct student *head,int num)
{
struct student *p,*p2;
p=head;
if(NULL==head){
printf("It is the empty linked list");
return head;
}
while((num!=p->StuNum)&&(NULL!=p->next)){
p2=p;
p=p->next;
//}去掉这个
if(num==p->StuNum){
if(head==p->next)
head=p->next;
else 
p2->next=p->next;
}
else
printf("can not find!\n");
}//放到这里来
return head;
}