c++遍历数组是,下标变量不能被赋值

问题:

找一个数组中最小元素时数组下表变量不能被赋值

注:InitList,InsertList,PrintValue函数正常;

#include <stdio.h>
#define MAXSIZE 10
typedef int ElemType;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct List{
    ElemType data[MAXSIZE];
    int length;
}sqList; 
void InitList(sqList &l);
bool InsertList(sqList &l,int i,ElemType e);
bool DeleteList(sqList &l,int i);

void PrintValue(sqList l);
int custom(sqList l){
    if(l.length=0){
        printf("空表\n");
    }
    int min=0;
    for(int i=0;i<l.length;i++){
        if(l.data[i]<l.data[i+1]){
            min=l.data[i];
        }
    } 
    return min;
}
int main() {
    sqList l;
    InitList(l);
    InsertList(l,1,3);
    InsertList(l,2,5);
    InsertList(l,3,2);
    InsertList(l,4,7);
    PrintValue(l);
    printf("%d",custom(l));
    return 0;
}
//init
void InitList(sqList &l){
    l.length=0;
}
//insert
bool InsertList(sqList &l,int i,ElemType e){
    if(i<1 || i>l.length+1){
        return false;
    }
    if(l.length>=MAXSIZE){
        return false; 
    }
    for(int j=l.length;j>=i-1;j--){
        l.data[j+1]=l.data[j];
    }
    l.data[i-1]=e;
    l.length++;
    return true;
}

//print
void PrintValue(sqList l){
    for(int i=0;i<l.length;i++){
        printf("%d\n",l.data[i]);
    }
}

图片说明

第21行那里的i+1越界了吧