3、5 TLE 救救孩子
查看原帖
3、5 TLE 救救孩子
516858
可能性的世界楼主2021/5/31 09:43
#include <iostream>
#include<stdio.h>
using namespace std;
struct link {
    int data;
    link* last;
    link* next;
};
int main()
{
    int a;
    link* head = NULL, * shift = NULL, * now = NULL;
    cin >> a >> a;
    for (int x = 0; x < a; x++) {
        int k;
        if (x == 0) {
            head = new link;
            cin >> k;
            head->data = k;
            head->next = head->last = NULL;
            shift = head;
        }
        else {
            cin >> k;
        logo:
            if (k <= (shift->data) && (shift->last == NULL)) {
                now = new link;
                now->next = shift;
                shift->last = now;
                now->last = NULL;
                now->data = k;
                head = shift = now;
                continue;
            }
            if ((k <= shift->data) && k >= (shift->last->data)) {
                now = new link;
                now->data = k;
                now->next = shift;
                now->last = shift->last;
                shift->last = now;
                now->last->next = now;
                shift = now;
                continue;
            }
            if (k >= (shift->data) && (shift->next == NULL)) {
                now = new link;
                now->last = shift;
                shift->next = now;
                now->next = NULL;
                now->data = k;
                shift = now;
                continue;
            }
            if ((k >= shift->data) && k <= (shift->next->data)) {
                now = new link;
                now->data = k;
                now->last = shift;
                now->next = shift->next;
                shift->next = now;
                now->next->last = now;
                shift = now;
                continue;
            }
            if (k <= shift->data) {
                shift = shift->last;
                goto logo;
            }
            if (k >= shift->data) {
                shift = shift->next;
                goto logo;
            }
        }
    }
    shift = head;
    for (int z = 0; z < a; z++) {
        printf("%d ", shift->data);
        shift = shift->next;
    }
}

怎么提高链表效率

2021/5/31 09:43
加载中...