#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE10000
#define SUCCESS0
#define OVERFLOW0
#define ERROR-1
typedef int ElemType;
typedef int Status;
typedef struct
{
ElemType *elem;
int length;}SqList;
Status InitList(SqList &L);
Status PrintElem(SqList L);
Status InitElem(SqList &L,ElemType e[],int len);
Status GetElem(SqList L,int i,ElemType &e);
int LocateElem(SqList L,ElemType e);
Status ListInsert(SqList &L,int i,ElemType e);
Status ListDelete(SqList &L,int i);
int main(){
SqList L;
ElemType elem[8]={4,5,2,1,25,5,5,5},e=1;InitList(L);InitElem(L,elem,8);printf("\ne=%d",e);GetElem(L,1,e);printf("\ne=%d",e);printf("\n1--Locate=%d",LocateElem(L,1));ListInsert(L,3,6);ListDelete(L,3);return0;}
Status InitList(SqList &L){L.elem=newElemType[MAXSIZE];if(!L.elem)exit(OVERFLOW);L.length=0;printf("init\n");returnSUCCESS;}
Status PrintElem(SqList L){
int i;printf("\n");for(i=0;i<L.length;i++)printf("%d ",L.elem[i]);returnSUCCESS;}
Status InitElem(SqList &L,ElemType e[],int len){
int i;for(i=0;i<len;i++)L.elem[i]=e[i];L.length=len;PrintElem(L);returnSUCCESS;}
Status GetElem(SqList L,int i,ElemType &e){if(i<1||i>L.length)exit(ERROR);
e=L.elem[i-1];returnSUCCESS;}
int LocateElem(SqList L,ElemType e){
int i;for(i=0;i<L.length;i++)if(L.elem[i]==e)return i+1;exit(ERROR);}
Status ListInsert(SqList &L,int i,ElemType e){if(i<1||i>L.length)exit(ERROR);if(L.length==MAXSIZE)exit(ERROR);
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;PrintElem(L);returnSUCCESS;}
Status ListDelete(SqList &L,int i){if(i<1||i>L.length)exit(ERROR);
int j;for(j=i;j<=L.length-1;j++)L.elem[j-1]=L.elem[j];--L.length;PrintElem(L);returnSUCCESS;}