#include <stdio.h> #include <stdlib.h> typedef struct student{ int num; char name[20]; int score; struct student *next; }student; void main(){ void sort(student *LA,student *LB); int n,m; scanf("%d %d",&n,&m); student *LA,*LB,*s,*p; LA=(student *)malloc(sizeof(student)); LB=(student *)malloc(sizeof(student)); LA->next=LB->next=NULL; p=LA; while(n--){ s=(student *)malloc(sizeof(student)); scanf("%d %s %d",&s->num,s->name,&s->score); s->next=NULL; p->next=s; p=s; } p=LB; while(m--){ s=(student *)malloc(sizeof(student)); scanf("%d %s %d",&s->num,s->name,&s->score); s->next=NULL; p->next=s; p=s; } sort(LA,LB); for(p=LA->next;p!=NULL;p=p->next){ printf("%d %s %d\n",p->num,p->name,p->score); } } void sort(student *LA,student *LB){ student *pre,*p,*minpre,*min,*s,*pres,*temp; for(p=LA->next;p->next!=NULL;p=p->next); p->next=LB->next; free(LB); for(pre=LA;pre->next!=NULL;pre=pre->next){ p=pre->next; s=p; pres=pre; min=p; minpre=pre; for(;s!=NULL;pres=s,s=s->next){ if(s->num<min->num){ min=s; minpre=pres; } } temp=p->next; pre->next=min; minpre->next=p; p->next=s->next; s->next=temp; } } |
Double click to view unformatted code.