# include <stdlib.h>
# include <stdio.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define List_Size 100
#define ListIncrement 10
typedef int ElemType;
typedef struct{
ElemType*elem;
int length;
int listsize;
}SqList;
int InitSqList(SqList &L){
L.elem=new ElemType[List_Size];
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=List_Size;
return OK;
}
void CreatSqList(SqList&L,int n){
int i;
for(i=0;i<n;i=i++){
scanf("%d",&L.elem[i]);
L.length++;
}
}
void Deatroy(SqList &L){
delete L.elem;
}
int ListInsert (SqList &L, int i, ElemType x) {
int j;
ElemType *p;
if (i < 1 || i > L.length+1){
return ERROR;
}
if (L.length >= L.listsize) {
p=(ElemType*)realloc(L.elem, (L.listsize+ListIncrement)*sizeof(ElemType));
if(!p)exit(OVERFLOW);
L.elem=p;
L.listsize=L.listsize+ListIncrement;
}
for(j=L.length-1;j>=i;j--)L.elem[j+1]=L.elem[j];{
L.elem[i]=x;
++L.length;
return OK;
}
}
int ListDelete(SqList &L,int i){
int j;
if(i<1||i>L.length)
return ERROR;
for(j=i-1;j<L.length-1;j++)
L.elem[j]= L.elem[j+1];
--L.length;
return OK;
}
int LocatElem(SqList L,ElemType x){
int i=1;
while(i<=L.length&&L.elem[i-1]!=x)i++;
if(i<=L.length)
return i;
else return ERROR;
}
void DispList(SqList L) {
int i;
for (i=0;i<L.length;i++)
printf("%d",L.elem[i]);
printf("\n");
}
void Contrary_Sq(SqList &La){
int i=0,temp;
for(i=0;i<La.length/2;i++){
temp=La.elem[i];
La.elem[i]= La.elem[La.length-1-i];
La.elem[La.length-1-i]=temp;
}
}
int main(){
SqList L;
int i,f;
i=3;
f=2020;
ElemType x=f;
InitSqList(L);
CreatSqList(L,5);
DispList(L);
printf("%d\n",L.length);
if(ListInsert(L,i,x))DispList(L);
if(ListDelete(L,i))DispList(L);
Contrary_Sq(L);
DispList(L);
return 0;
}