• ky0930


    //第二章线性表的记录
    //  main.c
    //  ds_excecise
    //
    //  Created by rouge s on 2020/9/28.
    //
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define ElemType int
    const int Range = 100;
    
    typedef struct LNODE{
        ElemType data;
        struct LNODE *next;
    }LNODE, *LinkList;
    
    // 函数声明集合
    LNODE* make(int n);
    void printLNODE(LNODE *p);
    void inverseprint(LNODE *p);
    int ip(LNODE *p);
    int DELmin(LNODE*p);
    int sort(LNODE *p);
    
    int main() {
        time_t t;
        srand((unsigned) time(&t));
        printf("
    开始了
    ");
        LNODE *p;
        p = make(5);
        printLNODE(p);
        sort(p);
        printf("
    
    ");
        printLNODE(p);
        printf("
    结束了
    ");
        return 0;
    }
    
    
    LNODE* make(int n){
        LNODE *head, *node, *end;//定义头节点,普通节点,尾部节点;
        head = (LNODE *)malloc(sizeof(LNODE));//分配地址
        end = head;         //若是空链表则头尾节点一样
        for (int i = 0; i < n; i++) {
            node = (LNODE *)malloc(sizeof(LNODE));
            node->data = rand()%Range;
            end->next = node;
            end = node;
        }
        end->next = NULL;//结束创建
        return head;
    }
    
    
    void printLNODE(LNODE *p){
        p = p->next;
        while( p != NULL){
            printf("%d - > ",p->data);
            p = p->next;
        }
    }
    
    void inverseprint(LNODE *p){
        p = p ->next;
        ip(p);
    }
    
    
    int ip(LNODE*p){
        if (p == NULL)
            return 0;
        LNODE *N = p;
        p = p ->next;
        ip(p);
        printf("%d - > ",N->data);
        return 0;
    }
    
    int DELmin(LNODE*p){
        if (p->next == NULL)
            return 0;
        LNODE *L1=p->next,*L2;
        int count = 1,flag = 1, min = L1->data;
        L1 = L1->next;
        while (L1 != NULL){
            count ++;
            if (L1->data < min){
                flag = count;
                min = L1->data;
            }
            L1 = L1->next;
        }
        printf("
    
    最小值是 %d
    
    flag是%d
    
    ",min,flag);
        L1 = p;
        for (count = 1; count <flag; count++){
            L1 =L1->next;
        }
        L2 = L1->next;
        L1->next = L2 ->next;
        free(L2);
        return 1;
    }
    
    int sort(LNODE *p){
        if (p -> next == NULL)
            return 0;
        LNODE *yuan=p;
        p = p ->next;
        int flag = 0;
        LNODE *ici;
        while ( flag !=1){
            flag =1;
            ici = p;
            while (p->next != NULL){
                if (p->data > p->next->data){
                    flag = 0;
                    int temp = p->data;
                    p->data = p->next->data;
                    p->next->data = temp;
                }
                p = p->next;
            }
        }
        printf("
    
    ");
        printLNODE(yuan);
        printf("
    
    ");
        return 1;
    }
    
  • 相关阅读:
    【C# 调用 Go 语言】
    Go语言多线程 (转)
    CodeSoft 2019 企业版打标签
    (转)FFT求频谱图和功率谱密度图
    使用NI-DAQmx进行振动数据采集
    CentOS7 安装配置笔记
    .net 调用 nsfwjs 进行视频鉴别
    Electron.Net + Linux + Blazor 初尝备忘录
    关于feign调用的时候,动态传url ,以及自定义head
    go使用excelize导出xls
  • 原文地址:https://www.cnblogs.com/gallien/p/13752741.html
Copyright © 2020-2023  润新知