原题链接:[编程入门]链表合并
解题思路:
注意事项:
参考代码
#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语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复