• 数据结构实验之链表六:有序链表的建立(SDUT 2121)


    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct node
    {
        int data;
        struct node *next;
    };
    int main()
    {
        int n;
        struct node *head,*tail,*p,*q,*t;
        scanf("%d",&n);
        head = new node;
        head -> next = NULL;
        tail = head;
        for(int i = 0; i < n; i ++)
        {
            p = new node;
            p -> next = NULL;
            scanf("%d",&p->data);
            if(head -> next == NULL){
                tail -> next = p;
                tail = p;
            }
            else {
                int f = 1;
                q = head;
                t = q -> next;
                while(t)
                {
                    if(p->data > t -> data){
                        q = q ->next;
                        t = t -> next;
                    }
                    else {
                        p->next =q ->next;
                        q -> next = p;
                        f = 0;
                        break;
                    }
                }
                if(f) {tail -> next = p;
                tail = p;}
            }
        }
        for(p = head -> next; p != NULL; p = p -> next)
        {
            if(p==head->next)printf("%d",p->data);
            else printf(" %d", p -> data);
        }
        printf("
    ");
        return 0;
    }
    
    
    
  • 相关阅读:
    http
    python的列表生成式
    flask的登陆验证
    脚本更新流程
    k8s中job和pod的区别
    k8s中一些常见概念
    supervisord部署和使用
    flask中config
    python类的继承super()的使用
    python中类的继承
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139496.html
Copyright © 2020-2023  润新知