解题思路:
注意事项:
参考代码
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<string.h> #define Change(x,y){int t;t =x;x=y;y=t;} typedef struct list{ int xuehao; int grade; struct list *next; }node,*Node; Node creat (int ); Node sort (Node ,Node); int main() { int n,m; Node head_a,head_b,head; scanf("%d%d",&n,&m); head_a = creat(n); head_b = creat(m); head = sort(head_a,head_b); while(head) { Node q; q = head; printf("%d %d\n",q->xuehao,q->grade); head= head->next; } return 0; } Node creat(int n) { int i; Node first,second; Node head; head = (Node)malloc(sizeof(node)); head->next = NULL; first = head; for(i=0;i<n;i++) { second = (Node)malloc(sizeof(node)); second->next = NULL; scanf("%d%d",&(*second).xuehao,&(*second).grade); first->next = second; first = second; } return (head); } Node sort(Node a,Node b) { Node head,q,p; int term=0; q = a; head = q; while(q->next) { q = q->next; } q->next = b->next; //连接 q = head->next; for(p=q;p!=NULL;p = p->next) { for(q=head->next;q->next!=NULL;q=q->next) { if(q->xuehao>q->next->xuehao) {Change(q->grade,q->next->grade);Change(q->xuehao,q->next->xuehao);} } } return head->next; }
:
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:602 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:774 |
【明明的随机数】 (C语言代码)浏览:785 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:609 |
1012题解浏览:861 |
1014题解浏览:484 |
字符逆序 (C语言代码)浏览:455 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:662 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:614 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:542 |