【代码】//文件名:sqlist.cpp
#include <stdio.h>
#include <malloc.h>
#define MaxSize 50
typedef int ElemType;
typedef struct
{ ElemType data[MaxSize];
int length;
} SqList;
void InitList(SqList *&L) //初始化线性表
{ L=(SqList *)malloc(sizeof(SqList));
L->length=0;
}
void DestroyList(SqList *L) //销毁线性表
{ free(L);
}
void CreateList(SqList *L,ElemType a[],int n) //建立顺序表
{ int i=0,k=0;
while(i<n)
{ L->data[i]=a[i];
k++;
i++;
}
L->length=k;
}
bool ListEmpty(SqList *L) //判断线性表是否为空表
{ return (L->length==0);
}
int ListLength(SqList *L) //求线性表长度
{ return (L->length);
}
void DispList(SqList *L) //输出线性表
{ for(int i=0; i<L->length; i++)
printf("%d ",L->data[i]);
printf("\n");
}
bool GetElem(SqList *L,int i,ElemType &e) //求线性表中第i个元素的值
{ if(i<1||i>L->length)
return false;
e=L->data[i-1];
retu