數(shù)據(jù)結(jié)構(gòu)與算法基礎(chǔ)(青島大學(xué)-王卓)

/*
線性表基本操作:?
InitList(&L)?// 初始化操作,建立一個空的線性表L?
DestroyList(&L) // 銷毀已存在的線性表L?
ClearList(&L) // 將線性表清空?
ListInsert(&L, i, e) // 在線性表L中第i個位置插入新元素e?
ListDelete(&L, i, &e) // 刪除線性表L中第i個位置元素,用e返回?
IsEmpty(&L) // 若線性表為空, 返回true, 否則false?
ListLength(&l) // 返回線性表L的元素個數(shù)?
LocateElem(&L, e) // L中查找與給定值e相等的原數(shù),若成功,返回該元素在表中的序號,否則返回0?
GetElem(&L, i, &e) //將線性表中L中的第i個位置元素返回給e?
*/
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW - 2
#define MAXSZIE 100
typedef int Status;
typedef char ElemType;
typedef struct {
ElemType *elem;
int length;
} SqList;
Status InitList_Sq(SqList &L) {?
L.elem = new ElemType[MAXSIZE];
if (!L.elem) exit(OVERFLOW);
L.length = 0;
return OK;
}
void DestroyList(SqList &L) {
if (L.elem) delete L.elem;
}
void ClearList(SqList &L) {
L.length = 0;
}
int GetLength(SqList &L) {
return (L.length);
}
int IsEmpty(SqList &L) {
if (L.length == 0) return 1;
return 0;
}
int GetElem(SqList &L, int i, ElemType &e) {
if (i < 1 ||| i > length) return ERROR;
e = L.elem[i - 1];
return OK;
}