回复 32楼 弟大勿勃
struct student *del(struct student *head,int num)
{
struct student *p1,*p2,*temp;
int flag=0;
if(head==NULL)
{
printf("\nThis list is null!\n");
return p1;
}
p1=head;
//为什么这里是p1指向head而不是head指向p1
loop:
while(p1->num!=num && p1->next!=NULL)
{
p2=p1;
//
p1=p1->next;
//
}
if(p1->num==num)
{
if(p1==head)
{
head=p1->next;
temp=p1;
p1=p1->next;
free(temp);
}
else
{
p2->next=p1->next;
temp=p1;
p1=p2->next;
free(temp);
}
printf("\nDeleat NO:%d succesed!\n",num);
n=n-1;
flag=1;
}
if(p1!=NULL)goto loop;
if(!flag)
{
printf("%d not been found!\n",num);
}
return head;
}
试试这个,我在我的函数体里试了还可以。