zoukankan      html  css  js  c++  java
  • 线性表-顺序表

    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    //结构定义
    #define maxSize 50
    typedef struct{
        int data[maxSize];
        int length;
    }SqList;
    
    //插入元素
    bool insertList(SqList &L,int i,int e){
        //顺序表是否已满
        if(L.length >= maxSize){
            return false;
        }
        //i是否合法
        if(i > L.length || i < 1){
            return false;
        }
    
        for(int index = L.length; index >= i; index--){
            data[index] = data[index-1];
        }
        data[i-1] = e;
        L.length++;
    
        return true;
    }
    
    //删除元素
    bool ListDelete(SqList &L,int i,int &e){
        //顺序表是否为空
        if(L.length <= 0){
            return false;
        }
        //i是否合法
        if(i < 1 || i > L.length){
            return false;
        }
    
        e = L.data[i-1];
        for(int index = i - 1; index < L.length-1; index++){
            L.data[index] = L.data[index+1];
        }
        L.length--;
        return true;
    }
    
    //定位元素
    int LocateElem(SqList &L,int e){
        for(int index = 0; index < L.length; index++){
            if(L.data[index] == e){
                return index+1;
            }
        }
        return 0;
    }
    

       

  • 相关阅读:
    Spring_Bean的配置方式
    Nginx Ingress设置账号密码
    2.2.4 加减运算与溢出
    2.2.5-2 补码乘法
    2.2.3 移位运算
    flask钩子函数
    flask的cookie、session
    循环冗余校验码
    海明校验码
    python中的 __call__()
  • 原文地址:https://www.cnblogs.com/buaaZhhx/p/12366367.html
Copyright © 2011-2022 走看看