#include
#include
#define NULL 0
#define LEN sizeof(struct info)
struct info
{
int num;
float score;
struct info *next;
};
int n;
struct info *creat(void)
{
struct info *head, *p1, *p2;
head=NULL;
n=0;
p1=p2=(struct info *)malloc(LEN);
printf("Please input the number and score:n");
scanf("%d%f", &p1->num, &p1->score);
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct info *)malloc(LEN);
scanf("%d%f", &p1->num, &p1->score);
}
p2->next=NULL;
free(p1);
return(head);
}
void print(struct info *head)
{
struct info *p;
p=head;
if(head)
do
{
printf("%d%5.1fn", p->num, p->score);
p=p->next;
}while(p!=NULL);
}
struct info *del(struct info *head, int num)
{
struct info *p1, *p2;
if(!head){printf("nlist null!n"); return(head);}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{ p2=p1; p1=p1->next; }
if(num==p1->num)
{ if(p1==head)
head=p1->next;
else
p2->next=p1->next;
free(p1);
printf("delete:%dn",num);
}
else
printf("%d not been found!n", num);
return(head);
}
struct info *insert(struct info *head, struct info *stud)
{
struct info *p0, *p1, *p2;
p1=head;
p0=stud;
if(!head)
{head=p0;
p0->next=NULL;}
else
{ while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;
}
else{p1->next=p0;p0->next=NULL;}
}
return(head);
}
main()
{
struct info *head, *stu;
int delnum;
head=creat();
print(head);
printf("nPlease input the del num:");
scanf("%d",&delnum);
while(delnum)
{
head=del(head, delnum);
print(head);
printf("nPlease input the del num:");
scanf("%d", &delnum);
}
printf("nPlease insert the record:");
stu=(struct info*)malloc(LEN);
scanf("%d%f", &stu->num, &stu->score);
while(stu->num!=0)
{
head=insert(head, stu);
printf("nPlease insert the record:");
stu=(struct info*)malloc(LEN);
scanf("%d%f", &stu->num, &stu->score);
}
free(stu);
print(head);
}



