前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >顺序存储 c++

顺序存储 c++

原创
作者头像
lascyb
发布2022-01-13 16:03:36
4150
发布2022-01-13 16:03:36
举报
文章被收录于专栏:PHP-轮子制造机PHP-轮子制造机
代码语言:javascript
复制
#define TRUE 1
#define FALSE 1
#define ERROR 0
#define MAX_SIZE 100
#define OK 1
/**顺序存储
 * 
 * */
class ShunList{
    typedef struct{
        int data;
    }ElemType;
    typedef struct{
        ElemType *data;
        int length;
    }SqList;
    static int initList(SqList &L){
        L.data=new ElemType[MAX_SIZE];
        if (!L.data) exit(OVERFLOW);
        return TRUE;
    }
    int GetElem(SqList L,int i,ElemType &e){
        if (i<1||i>L.length) return ERROR;
        e=L.data[i-1];
        return OK;
    }
    static int LOC(SqList L,ElemType e){
        for (int i = 0; i < L.length; ++i) {
//            if (L.data[i] == e){
//                return i+1;
//            }
        }
        return 0;
    }
    static int  ListInsert_Sq(SqList &L,int i,ElemType e){
        if (i<1||i>L.length) return ERROR;
        if (L.length==MAX_SIZE)return ERROR;
        for (int j = L.length-1; j >= i-1 ; j--) {
            L.data[j+1]=L.data[j];
        }
        L.data[i-1]=e;
        L.length++;
        return OK;
    }
    int ListDelete(SqList &L,int i,ElemType &e){
        /**时间复杂度
         * i=1  2   3   ... n
         *  n-1 n-2 n-3 ... n-i
         *  (n-1)/2
         * O(n)
         * */
        if (i<1||i>L.length) exit(ERROR);
        e=L.data[i-1];
        for (int j = i-1; j < L.length-1; ++j) {
            L.data[j]=L.data[j+1];
        }
        L.length--;
        return OK;
    }
    //线性表合并 两个集合求并集 A ∪ B
    void union_A_B(SqList &La,SqList Lb){

    }
};

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档