解题思路:
链式排序不是那么好弄。。所以用了交换
注意事项:
参考代码:
/*lb*/ #include<stdio.h> #include<stdlib.h> typedef struct student { int num; int score; struct student *next; }stu; stu *create(stu *L,int n) { int i; stu *p,*q; L = (stu *)malloc(sizeof(stu)); q = L; L->next = NULL; for(i = 0; i < n; i++)//尾插 { p = (stu *)malloc(sizeof(stu)); p->next = NULL; scanf("%d%d",&p->num,&p->score); q->next = p; q = p; } return L; } stu *addandsort(stu *L1,stu *L2) { stu *p,*q,*min; int t; p = L1; while(p->next!=NULL) p = p->next; p->next = L2->next; p = L1->next; while(p) { min = p; q = p->next; while(q) { if(min->num>q->num) min = q; q = q->next; } t = p->num;p->num = min->num;min->num = t; t = p->score;p->score = min->score;min->score = t; p = p->next; } return L1; } void print(stu *L) { stu *p = L->next; while(p) printf("%d %d\n",p->num,p->score),p = p->next; } int main() { stu *L1,*L2,*L3; int n,m; scanf("%d%d",&n,&m); L1 = create(L1,n); L2 = create(L2,m); L3 = addandsort(L1,L2); print(L3); return 0; }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:810 |
C二级辅导-计负均正 (C语言代码)浏览:643 |
数组输出 (C语言代码)浏览:811 |
C语言训练-字符串正反连接 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:466 |
C语言程序设计教程(第三版)课后习题1.6 (C++代码)浏览:909 |
【出圈】 (C语言代码)浏览:824 |
【简单计算】 (C语言代码)浏览:642 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:956 |
完数 (C语言代码)浏览:757 |