顺序表插入

cpp 复制代码
#include <iostream>


#include <stdio.h>
#include <stdlib.h>

using namespace std;

#define MaxSize 10
typedef struct {
    int data[MaxSize];
    int length;
}SeqList;

void InitList(SeqList &L ){
    for(int i = 0 ; i < L.length ; i++){
        L.data[i] = 0;
    }
}
int InserList(SeqList &L , int i, int e){
    if(i > MaxSize || i<1){
        return -1;
    }
    if(MaxSize==L.length){
        return -2;
    }

    for(int j = L.length ; j>=i ;j--){
        L.data[j] = L.data[j-1];
    }
    L.data[i-1] = e;
    L.length++;
}

void  show(SeqList L){
    for(int i = 0 ; i< MaxSize ; i++){
        printf("List 【%d】:%d \n",i,L.data[i]);
    }

}

int main(){
    SeqList L;
    InitList(L);
    InserList(L,0,888);
    printf("%d \n",InserList(L,0,888));
    printf("length: %d \n",L.length);
    show(L);




    return 0;
}
相关推荐
垆边人似月.13 分钟前
华为算法题:最长连续递增子序列的变
数据结构·算法·leetcode
YOLO数据集集合14 分钟前
机器学习二分类预测算法组合工具:12种算法、113种组合的批量建模方案8031期
算法·机器学习
longlongzihan25 分钟前
LeetCode 56合并区间:排序与贪心
c++·算法·leetcode
学术小李1 小时前
cudaMalloc第一个参数为何是指针的指针
算法
kukubuzai1 小时前
二分查找系列一
数据结构·算法·leetcode
老歌老听老掉牙1 小时前
动态规划:从递归到最优决策的算法艺术
算法·动态规划
朔北之忘 Clancy1 小时前
2024 CSP-J 第二轮真题解析
c++·算法·青少年编程·noip·csp·信奥赛·noi
小七在进步2 小时前
类和对象(五)
java·开发语言·算法
就叫年华吧丶2 小时前
长文档点目录定位总是不准?一个 content-visibility + 平滑滚动引发的连环坑(Vue3 实战)
前端·javascript·算法·vue