链表问题,大家帮帮忙呀,明天考试哦,急
帮忙具体解释下这个程序哦,明天考试哦,急 #include<stdio.h>
#include<string.h>
#include<malloc.h>
#define LEN sizeof(struct score)
struct score
{char num[4];
int score;
struct score *next;
};
struct score *creat(void)
{struct score *head;
struct score *p1,*p2;
int i ;
for(i=0;i<2;i++)
{ p1 =(struct score *) malloc(LEN);
if(i==0) head=p2=p1;
else
{p2->next=p1;
p2=p1;}
scanf("%s %d",p1->num,&p1->score);
}
p1->next=NULL;
return (head);
}
struct score* insert (struct score *head, struct score *nscore)
{
struct score *p0,*p1,*p2;
p1=head;
p0=nscore;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while(strcmp(p0->num,p1->num)>0&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;}
if(strcmp(p0->num,p1->num)<0)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;
p0->next=NULL;
}
} return head
}
void main()
{
struct score *p1,*p2,*head;
head=creat();
printf("please input a shuju");
p1 =(struct score *) malloc(LEN);
scanf("%s %d",p1->num,&p1->score);
insert(head,p1);
p2=head;
while(p2)
{printf( " %s , %d\n",p2->num,p2->score);p2=p2->next;}
}