#include<stdio.h>
#include<stdlib.h>
#define ok 1
#define ERROR 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LIST_INCREMENT 10
typedef struct List{
ElemType *elem;
int length;
int listSize;
}Sqlist;
Status initList(Sqlist *L){
L->elem=(ElemType *)malloc(100 * sizeof(ElemType));
if(L->elem==NULL){
return ERROR;
}
L->length=0;
L->listSize=LIST_INIT_SIZE;
}
Status insertList(Sqlist *L,int i,ElemType e){
if(i<1 || L->length+1){
return ERROR;
}
if(L->length>=L->listSize){
ElemType *newbase=(ElemType *)realloc(L->elem,(L->listSize+LIST_INCREMENT)*sizeof(ElemType));
if(newbase == NULL) exit(OVERFLOW);
L->elem=newbase;
L->listSize+=LIST_INCREMENT;
}
for(int j=L->length-1;j>=i-1;--i){
L->elem[j+1]=L->elem[j];
}
L->elem[i-1]=e;
++L->length;
return ok;
}
int main(){
Sqlist L;
initList(&L);
insertList(&L,1,12);
return 0;
}