#include <stdio.h> #include <malloc.h> typedef struct node{ int id; int grade; struct node *next; }NODE; NODE *creat(int n){ struct node *head,*p,*q; head = (struct node*)malloc(sizeof(struct node)); head->next = NULL; while(n>0){ p = (struct node*)malloc(sizeof(struct node)); scanf("%d%d",&p->id,&p->grade); if(head->next == NULL){ p->next = head->next; head->next = p; q = p; } else{ p->next = q->next; q->next = p; q = p; } n--; } return head; } NODE *merge(NODE *head,NODE *head1){ NODE *p; p = head; while(p->next!=NULL) p = p->next; p->next = head1->next; head1->next = NULL; return head; } int sort(NODE *head,int n){ NODE *p; int id,grade; while(n>0){ for(p = head->next;p->next!=NULL;p=p->next){ if(p->id > p->next->id){ grade = p->grade; id=p->id; p->grade = p->next->grade; p->id = p->next->id; p->next->grade = grade; p->next->id = id; } } n--; } p = head->next; while(p!=NULL){ printf("%d %d\n",p->id,p->grade); p = p->next; } return 0; } main(){ NODE *head,*head1; int n,m; scanf("%d%d",&n,&m); head = creat(n); head1 = creat(m); head = merge(head,head1); sort(head,n+m); return 0; } |
Double click to view unformatted code.