zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    医学影像分割之HIP
    c++画分形之Julia集与Mandelbrot集
    趣题一道
    华山论剑常用角点检测与角点匹配方法比较
    改变鼠标样式
    Unity3D Pro 利用摄像头产生俯视地图效果
    unity3D小地图教程
    WebBrowser网址中特殊字符的问题
    打开多个unity3D项目 (项目多开)
    u3d按住鼠标右键才转动摄像机的方法
  • 原文地址:https://www.cnblogs.com/gallien/p/13752741.html
Copyright © 2011-2022 走看看