数据结构与算法 – 表 – 线性表的顺序表示
线性表的顺序结构与实现
前提
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef struct {
ElemType* elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList& L)
{
L.elem = (ElemType*)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if (!L.elem) exit(OVERFLOW);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return OK;
}
向线性表中插入元素
Status ListInsert_Sq(SqList& L, int i, ElemType e)
{
if (i < 1 || i > L.length