线性表的基本操作:增加,删除,修改,查询
#define LIST_INIT_SIZE 10 // 线性表存储空间初始分配量
#define LIST_INCREMENT 2 // 线性表存储空间的分配增量
typedef int ElemType;
// 采用线性表的动态分配顺序存储结构
struct SqList
{
ElemType *elem; // 存储空间基址
int length; // 当前长度
int listsize; // 当前分配的存储容量(以sizeof(ElemType)为单位)
};
void InitList(SqList &L){
// 构造一个空的顺序线性表L
L.elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (!L.elem)
exit(OVERFLOW); // 存储分配失败
L.length = 0; // 空表长度为0
L.listsize = LIST_INIT_SIZE; // 初始存储容量
}