#include<stdio.h> #include<stdlib.h> typedef struct SNode { int num; int score; struct SNode * next; }SNode, *LinkSList; LinkSList Create_List(int n) { LinkSList L; SNode *r, *s; int i=0, num, score; L = (LinkSList)malloc(sizeof(SNode)); L->num = 0; L->score = 0; r = L; while(i<n) { scanf("%d %d", &num, &score); s = (SNode *)malloc(sizeof(SNode)); s->num = num; s->score = score; r->next = s; r = s; i++; } r->next = NULL; return L; } LinkSList merge(LinkSList a, LinkSList b) { SNode *p = a->next; while(p->next!=NULL) { p = p->next; } p->next = b->next; free(b); return a; } LinkSList order(LinkSList a) { SNode *p, *q, *min; int num, score; p = a->next; for( ; p->next!=NULL; p = p->next) { min = p; for(q=p->next; q!=NULL; q = q->next) { if(q->num < min->num) min = q; } if(min != p) { num = p->num; score = p->score; p->num = min->num; p->score = min->score; min->num = num; min->score = score; } } return a; } void displayList(LinkSList L) { SNode *p; p = L->next; while(p!=NULL) { printf("%d %d\n", p->num, p->score); p = p->next; } } void main() { LinkSList A, B; int n, m; scanf("%d %d", &n, &m); A = Create_List(n); B = Create_List(m); A = merge(A, B); A = order(A); displayList(A); } |
Double click to view unformatted code.