#include"iostream.h"
struct
student
{
long
num;
int
score;
student
*next;
};
student
*creat();
void
print(student
*head);
student
*insert(student
*head,student
*stud);
student
*del(student
*head,long
num);
void
main()
{
student
*head=NULL,*stud;
long
num;int
score;
cout<
建立学号、成绩:"<
head=creat();
cout<
print(head);
cout<>num;
while(num>0)
{
cout<>score;
stud=new
student;
stud->num=num;
stud->score=score;
head=insert(head,stud);
cout<>num;
}
cout<
print(head);
cout<>num;
while(num>0)
{
head=del(head,num);
cout<>num;
}
cout<
print(head);
}
student
*creat()
{
student
*head,*p1,*p2;
long
num;int
n=0;
head=NULL;
p1=new
student;
cout<
cin>>num;
while(num>0)
{
n++;
p1->num=num;
cout<>p1->score;
if
(n==1)
head=p1;
p2=p1;
p1=new
student;
p2->next=p1;
cout<
cin>>num;
}
p2->next=NULL;
return(head);
}
void
print(student
*head)
{
student
*p;
p=head;
}while(p!=NULL)
{
cout<num<
"<score<
p=p->next;
}
student
*del(student
*head,long
num)
{
student
*p1,*p2;
p1=head;
if(head==NULL)
cout<
null!"<
else
if(num==head->num)
head=head->next;
else
{
while(p1->num!=num
&&
p1->next!=NULL)
{
p2=p1;p1=p1->next;}
if
(p1->num==num)
{
if(p1->next==NULL)
p2->next=NULL;
else
p2->next=p1->next;
}
else
cout<
find!"<
}
delete
p1;
return(head);
}