#include<stdio.h> #include<malloc.h> typedef struct student { char jb[6]; char xh[15]; int score; }stu; typedef struct Node { stu date; struct Node *next; }SLNode; void ListInitiate(SLNode **head)//初始化 { *head=(SLNode *)malloc(sizeof(SLNode)); (*head)->next=NULL; } int ListInsert(SLNode *head,int i,stu x)//插入 { SLNode *p,*q; int j; p=head; j=-1; while(p->next!=NULL && j<i-1) { p=p->next; j++; } if(j!=i-1) { printf("插入参数位置错误! "); return 0; } q=(SLNode *)malloc(sizeof(SLNode)); q->date=x; q->next=p->next; p->next=q; return 1; } int ListLength(SLNode * head)//长度 { SLNode *p=head; int size=0; while(p->next!=NULL) { p=p->next; size++; } return size; } int ListDelete(SLNode *head,int i,stu *x)//删除 { SLNode *p,*q; int j; p=head; j=-1; while(p->next!=NULL &&p->next->next!=NULL&&j<i-1) { p=p->next; j++; } if(j!=i-1) { return 0; } q=p->next; *x=q->date; p->next=p->next->next; free(q); return 1; } int ListGet(SLNode *head,int i,stu *x)//取 { SLNode *p; int j; p=head; j=-1; while(p->next!=NULL &&j<i) { p=p->next; j++; } if(j!= i) { return 0; } *x=p->date; return 1; } main() { SLNode *head,*head1,*head2; int t,n,m; stu s,k; int j=0,x=0,i=0; ListInitiate(&head); ListInitiate(&head1); ListInitiate(&head2); scanf("%d",&n); while(n--) { scanf("%s%s%d",&s.jb,&s.xh,&s.score); ListInsert(head,ListLength(head),s); } scanf("%d",&m); while(m--) { scanf("%s%s%d",&s.jb,&s.xh,&s.score); ListInsert(head1,ListLength(head1),s); } while(j+i<ListLength(head)+ListLength(head1)&&(j<ListLength(head)&&i<ListLength(head1))) { ListGet(head,j,&s); ListGet(head1,i,&k); if(s.score>=k.score) { ListInsert(head2,x,s); j++; x++; } else { ListInsert(head2,x,k); i++; x++; } } if(j<ListLength(head)) while(j<=ListLength(head)-1) { ListGet(head,j,&s); ListInsert(head2,x,s); x++; j++; } else if(i<ListLength(head1)) { while(i<=ListLength(head1)-1) { ListGet(head1,i,&s); ListInsert(head2,x,s); x++; i++; } } for(i=0;i<ListLength(head2);i++) { ListGet(head2,i,&s); printf("%s %s %d\n",s.jb,s.xh,s.score); } }
原文:http://www.cnblogs.com/yc721274287/p/4438357.html