线性表插入操作,查错问题

该线性表插入操作未报错,但是不能插入数据,程序运行没问题

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

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef int Status;

//动态存储方式
#define LIST_INIT_SIZE 100
#define LIST_INCREMENT 10
typedef int ElemType;
typedef struct {
    ElemType *elem;//存储空间地址
    int length;//当前长度
    int listsize;//当前分配的存储容量
} SqList;

Status InitList_Sq(SqList &L) {
    L.elem = (ElemType*)malloc(LIST_INIT_SIZE);
    if (!L.elem)return ERROR;
    L.length = 0;
    L.listsize = LIST_INIT_SIZE;
    return OK;
}

Status ListInsert_Sq(SqList &L, int i, ElemType e) {
    ElemType *p;
    if (i < 1 || i > L.length)
        return ERROR;
    if (L.length >= L.listsize) {
        ElemType *newbace = (ElemType*)realloc(L.elem, (L.listsize + LIST_INCREMENT) * sizeof(ElemType));
        if (!newbace)
            return ERROR;
        L.elem = newbace;
        L.listsize += LIST_INCREMENT;
    }
    ElemType *q = &(L.elem[i - 1]);
    for (p = &(L.elem[L.length - 1]); p >= q; --p) {
        *(p + 1) = *p; //元素后移
    }
    *q = e;
    ++L.length;
    return OK;
}

void disList(SqList L) {
    for (int i = 1; i <= L.length; i++) {
        printf("%d ", L.elem[i - 1]);
    }
    printf("\n");
}

int main() {
    int a[8] = {1, 2, 3, 4, 5, 100, 200, 300};
    int i, j, e = 586;
    SqList List;
    InitList_Sq(List);
    for (i = 1, j = 0; i <= 8; i++, j++)
        ListInsert_Sq(List, i, a[j]);
    printf("\n初始元素序列\n");
    disList(List);
    ListInsert_Sq(List, 3, e);
    printf("\n插入e元素后的元素序列\n");
    disList(List);
    return 0;
}

img


上图是运行结果,刚学,不懂为啥这样,知道原因的朋友欢迎指错,感谢您。

你第一次插入的时候,i就大于了L.length,不直接返回ERROR了吗