• 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;
    }
    
  • 相关阅读:
    计算机网络拓扑结构
    中继器,集线器,网桥,交换机,路由器
    网络层次模型
    广播域和冲突域
    Tomcat
    Log4j
    Eclipse实用快捷键
    WebService是什么?
    定时任务处理-Quartz
    MySQL内存表-临时表
  • 原文地址:https://www.cnblogs.com/gallien/p/13752741.html
Copyright © 2020-2023  润新知