求告诉我,我的顺序表插入哪个错了。复制的有点乱,在编辑器排整齐了

#include <stdio.h>
#include<stdlib.h>
#define  MAXSIZE 100
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef  struct {
    ElemType  *elem;                                   //指向数据元素的基地址
    int  length;                                              //线性表的当前长度
} SqList;
Status InitList_Sq(SqList *L) {
    //构造一个空的顺序表L
    L->elem=new ElemType[MAXSIZE];      //为顺序表分配空间
    if(!L->elem) exit(OVERFLOW);               //存储分配失败
    L->length=0;                                           //空表长度为0
    return OK;
}
Status CreateList_Sq(SqList &L,int n) {
    int i;
    for (i=0; i<n; n++){
    scanf("%d",&L.elem[i]);
}

}
Status ListInsert_Sq(SqList &L,int i,ElemType e) {
    int j;
    for (j=L.length-1; j>=i-1; j--){
    
        L.elem[j+1]=L.elem[j];}
    L.elem[i-1]=e;
    ++L.length;
    return OK;
}
void TraverseList_Sq(SqList &L) {
    int j;
    for (j=0; j<L.length; j++) {

        printf("%d",L.elem[j]);
    }
}
void DestroyList_Sq(SqList &L) {
    if (L.elem) delete[]L.elem;    //释放存储空间
}
int main() {
    SqList L;
    int i,n,e;
    InitList_Sq(&L);
    scanf("%d",&n) ;//提示:输入元素个数:
    L.length=n;


    CreateList_Sq(L,n);
    TraverseList_Sq(L);          //遍历输出插入前线性表数据元素
    //提示:在顺序表中输入新元素插入的位置和数据:
    scanf("%d",&i);
    scanf("%d",&e);
    ListInsert_Sq(L,i,e);



    //在此处编写 ListInsert_Sq函数的调用语句
    TraverseList_Sq(L);
    DestroyList_Sq(L);
    return 0;
}

#include <stdio.h>
#include<stdlib.h>
#define  MAXSIZE 100
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef  struct {
    ElemType  *elem;                                   //指向数据元素的基地址
    int  length;                                              //线性表的当前长度
} SqList;
Status InitList_Sq(SqList *L) {
    //构造一个空的顺序表L
    L->elem=new ElemType[MAXSIZE];      //为顺序表分配空间
    if(!L->elem) exit(OVERFLOW);               //存储分配失败
    L->length=0;                                           //空表长度为0
    return OK;
}
Status CreateList_Sq(SqList &L,int n) {
    int i;
    for (i=0; i<n; i++){  //是i++ 不是n++
        scanf("%d",&L.elem[i]);
    }

}
Status ListInsert_Sq(SqList &L,int i,ElemType e) {
    int j;
    for (j=L.length-1; j>=i-1; j--){

        L.elem[j+1]=L.elem[j];}
    L.elem[i-1]=e;
    ++L.length;
    return OK;
}
void TraverseList_Sq(SqList &L) {
    int j;
    for (j=0; j<L.length; j++) {

        printf("%d ",L.elem[j]);
    }
    printf("\n");
}
void DestroyList_Sq(SqList &L) {
    if (L.elem) delete[]L.elem;    //释放存储空间
}
int main() {
    SqList L;
    int i,n,e;
    InitList_Sq(&L);
    scanf("%d",&n) ;//提示:输入元素个数:
    L.length=n;



    CreateList_Sq(L,n);
    TraverseList_Sq(L);          //遍历输出插入前线性表数据元素
    //提示:在顺序表中输入新元素插入的位置和数据:
    scanf("%d",&i);
    scanf("%d",&e);
    ListInsert_Sq(L,i,e);



    //在此处编写 ListInsert_Sq函数的调用语句
    TraverseList_Sq(L);
    DestroyList_Sq(L);
    return 0;
}

img

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img


Status CreateList_Sq(SqList &L,int n)  // for里 i++


您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632