typedef int ElementType;/*元素类型定义*/
/*1.定义*/
#define MaxSize 50
struct SqList
{
ElementType data[MaxSize];
int length;
};
/*2.操作*/
struct SqList *InitSqList(){
struct SqList *L=(struct SqList*)malloc(sizeof(struct SqList));
L->length=0;
return L;
}
bool ListInsert(struct SqList *L,int i,ElementType 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;
}
bool ListDelete(struct SqList *L,int i){
if(i<1||i>L->length)
return false;
for(int j=i;j<L->length;j++)
L->data[j-1]=L->data[j];
L->length--;
return true;
}
int LocateElem(struct SqList *L,ElementType e){
for(int i=0;i<L->length;i++)
if(L->data[i]==e)
return i+1;
return 0;
}
void ReadSqList(struct SqList *L){
int i;
if(L->length==0){
printf("线性表为空!\n");
}
else {
for( i=0;i<L->length-1;i++)
printf("%d ",L->data[i]);
printf("%d\n",L->data[i]);
}
}
void DestroySqList(struct SqList *L){
free(L);
}