#include <iostream>
#include <stdio.h>
#define MaxSize 50
typedef int ElemType;
typedef struct {ElemType data[MaxSize];int length;
}SqList;
bool ListInsert(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; j--) {L.data[j]=L.data[j-1];}L.data[i-1]=e;L.length++;return true;
}
void PrintList(SqList L)//打印顺序表
{for (int i = 0; i < L.length; ++i) {printf("%d ",L.data[i]);}printf("\n");
}
bool ListDelete(SqList &L,int i,ElemType &e)//删除数据{if(i<1 || i>L.length){return false;}e=L.data[i-1];for (int j = i; j < L.length; ++j) {L.data[j-1]=L.data[j];}L.length--;return true;};
int LocateElem(SqList L,ElemType e)//查找数据
{for (int j = 0; j < L.length; ++j) {if(L.data[j]==e){return j+1;}}return 0;
}
int main() {SqList L;bool ret;ElemType del;L.data[0]=1;L.data[1]=2;L.data[2]=3;L.length=3;ret=ListInsert(L,2,60);if(ret){PrintList(L);}else{printf("insert is not successful\n");}printf("*********************************\n");ret=ListDelete(L,3,del);if(ret){PrintList(L);printf("delete = %d\n",del);}else{printf("delete is not successful\n");}printf("*********************************\n");ret=LocateElem(L,60);if(ret){PrintList(L);printf("location = %d\n",ret);}else{printf(" is not successful\n");}return 0;
}