zoukankan      html  css  js  c++  java
  • 线性表的应用

    #include <stdio.h>
    #include <stdlib.h>
    #define LIST_INIT_SIZE  100
    #define LISTINCREMENT  10
    typedef struct{
        int *elem;
        int length;
        int listsize;
    }SqList;
    void InitList_Sq(SqList &L){
        L.elem = (int *)malloc(LIST_INIT_SIZE * sizeof(int));
        //if(! L.elem)exit(OVERFLOW);
        L.length = 0;
        L.listsize = LISTINCREMENT;
        printf("初始化成功
    ");
    }//InitList_Sq
    void ListInsert_Sq(SqList L,int i,int e){
        if(L.length>=L.listsize){
            int *newbase = (int *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof
            (int));
            //if(!newbase)exit(OVERFLOW);
            L.elem = newbase;
            L.listsize += LISTINCREMENT; 
        } 
        int *q = &(L.elem[i-1]);
        for(int *p = &(L.elem[L.length - 1]);p>=q;--p)*(p+1) = *p;
        *q = e;
        ++L.length;
        printf("成功
    "); 
    }//ListInsert_Sq
    void ListDelete_Sq(SqList L,int i,int e){   
        int *p = &(L.elem[i-1]);
        e = *p;
        int *q = L.elem + L.length - 1;
        for(++p;p<=q;++p) *(p-1)=*p;
        --L.length;
        printf("你要删除的值:%d
    ",e); 
    }//ListDelete_Sq
    void main(){
        int e=0;
        SqList L;
        int i=0;
        int k;
        printf("欢迎进入系统:
    ");
        int j=1;
        //scanf("%d
    ",&j);
        InitList_Sq(L);
        while(j==1){
        printf("插入值选1,删除选2.
    ");
        printf("请选择你想要进行的操作: 
    ");
        scanf("%d", &k);
        if(k==1){
        printf("请输入你想要插入的位置:"); 
        scanf("%d", &i);
        printf("请输入你想要输入的数据: "); 
        scanf("%d", &e);
        ListInsert_Sq(L,i,e);
        k=0;j=0;
        printf("请选择是否继续,继续选择1,退出选择2:
    ");
        scanf("%d", &j);
        }
        if(k==2){
        printf("请输入你想要删除的数据的位置: ");
        scanf("%d", &i);
        ListDelete_Sq(L,i,e);
        k=0;j=0;
        printf("请选择是否继续,继续选择1,退出选择2:
    ");
        scanf("%d", &j);
        }
        }
        return 0;
    }
  • 相关阅读:
    Python第二弹--------类和对象
    Python第一弹--------初步了解Python
    Java标记接口
    CentOS7下的YUM源服务器搭建详解,过程写的很详细(转)
    CentOS7.0安装Nginx 1.10.0
    QT中C++与Html端通信例子
    QT基础:QMainWindow学习小结
    QT基础:QT 定时器学习
    QT3D场景快速绘制入门学习
    QT编译错误:cannot find file: *.pro
  • 原文地址:https://www.cnblogs.com/chang1203/p/5925034.html
Copyright © 2011-2022 走看看