解题思路:

注意事项:

参考代码:

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <malloc.h>

typedef struct _node

{

int member;//学号

int score;//分数

struct _node* next;

}NODE;

NODE* add(NODE* head,int member,int score);//创建节点的函数

void link(NODE* head1,NODE* head2);//链接函数

void sort(NODE* head,int number1);//排序函数

int main()

{

int member = 0;

int score = 0;

NODE* head = NULL;

int number1 = 0;

int number2 = 0;

int pow = 0;//用来计数创建好的成员的变量;

scanf("%d%d", &number1, &number2);//第一个链表成员的数量,第二个链表成员的数量

do

{

scanf("%d%d", &member, &score);

head=add(head, member, score);

if ((++pow) == number1)

break;

} while (1);

NODE* head1 = head;//第一个链表的头指针

pow = 0;

head = NULL;

do

{

scanf("%d%d", &member, &score);

head = add(head, member, score);

if ((++pow) == number2)

break;

} while (1);

NODE* head2 = head;//第二个链表的头指针

link(head1,head2);//链接

sort(head1,number1+number2);

NODE* move = head1;

do

{

printf("%d %d\n", move->member, move->score);//最终的打印结果

move = move->next;

} while (move != NULL);

return 0;

}

void sort(NODE* head, int number1)

{

NODE* move=head;//移动指针

int i = 0;

int tem = 0;

while(1)

{

while(move->next!=NULL)

{

if (move->member > (move->next)->member)

{

tem = (move->next)->member;

(move->next)->member = move->member;

move->member = tem;

tem = (move->next)->score;

(move->next)->score = move->score;

move->score = tem;//变换顺序

}

move = move->next;

}

move = head;

if (++i == number1 - 1)

{

break;//冒泡循环只需要循环总节点数-1次就可以排好序

}

}

}

void link(NODE* head1,NODE* head2)

{

NODE* move = head1;

while (1)

{

if (move->next == NULL)//遍历

{

break;

}

move = move->next;

}

move->next = head2;

}

NODE* add(NODE* head, int member, int score)

{

NODE* p = (NODE*)malloc(sizeof(NODE));

if (p ==NULL)

{

printf("内存分配失败!");

}

p->member = member;

p->score = score;

NODE* last = head;//把头指针赋给尾指针;

if (last)

{

while (last->next)

{

last = last->next;

}

last->next = p;

}

else

{

head = p;

}

return head;

}


点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论