为什么这个程序第一个结点删不掉啊
#include<iostream>#include<string>
using namespace std;
struct student
{
int num;
float score;
char name;
struct student *next;
};
void del(student *head,int x,int n)
{
student *p1,*p2;
p1=head->next;
p2=head;
int i;
if(head->num==x)
{
head=p1;
}
else
{
for(i=1;i<n;i++)
{
if(p1->num==x)
p2->next=p1->next;
else
{
p1=p1->next;
p2=p2->next;
}
}
}
}
int main()
{
student *p1,*p2,*head,a;
head=p2=p1=&a;
cin>>a.name>>a.num>>a.score;
int i,n=1,x;
for(;p1->num!=0;n++)
{
if(n==1)
{
head=&a;
}
else
{
p1=new student;
cin>>p1->name>>p1->num>>p1->score;
p2->next=p1;
p2=p1;
}
}
cin>>x;
del(head,x,n);
for(i=0;i<n-1;i++)
{
if(head->num==0)
{
break;
}
cout<<head->name<<" "<<head->num<<" "<<head->score;
cout<<endl;
head=head->next;
}
return 0;
}