解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
typedef struct Link_List {
int num;
int mark;
struct Linke_List* next;
}Node;
Node* headera = malloc(sizeof(Node));
Node* headerb = malloc(sizeof(Node));
int a, b, i, number, grade;
if (headera != NULL && headerb != NULL) {
headera->next = NULL;
headerb->next = NULL;
}
Node* taila = headera;
Node* tailb = headerb;
scanf("%d", &a);
scanf("%d", &b);
for (i = 1; i <= a; i++)
{
Node* nodea = malloc(sizeof(Node));
scanf("%d", &number);
scanf("%d", &grade);
if (nodea != NULL)
{
nodea->num = number;
nodea->mark = grade;
nodea->next = NULL;
}
taila->next = nodea;
taila = nodea;
}
for (i = 1; i <= b; i++)
{
Node* nodeb = malloc(sizeof(Node));
scanf("%d", &number);
scanf("%d", &grade);
if (nodeb != NULL)
{
nodeb->num = number;
nodeb->mark = grade;
nodeb->next = NULL;
}
if (taila != NULL) {
tailb->next = nodeb;
tailb = nodeb;
}
}
if (taila != NULL) {
taila->next = headerb->next;
}
Node* Current = headera->next;
if (Current != NULL)
{
Node* Next = Current->next;
}
int t;
while (Current != NULL)
{
Node* Next = Current->next;
while(Next != NULL)
{
if (Current->num > Next->num)
{
t = Current->num;
Current->num = Next->num;
Next->num = t;
t = Current->mark;
Current->mark = Next->mark;
Next->mark = t;
}
Next = Next->next;
}
Current = Current->next;
}
Current = headera->next;
while (Current != NULL)
{
printf("%d ", Current->num);
printf("%d\n", Current->mark);
Current = Current->next;
}
return 0;
}
0.0分
0 人评分