Jerry


私信TA

用户名:dotcpp0595068

访问量:763

签 名:

等  级
排  名 17222
经  验 779
参赛次数 0
文章发表 18
年  龄 0
在职情况 学生
学  校 深圳大学
专  业

  自我简介:

TA的其他文章

链表合并+排列
浏览:45

解题思路:

注意事项:

参考代码:

#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 人评分

  评论区

  • «
  • »