我们先给出线性表的相关数据结构的定义(严蔚敏 清华大学数据结构(C语言版))
#define INIT_LIST_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OK 1
#define INFEASIBLE -1
#define OVERFLOW -2
typedef struct {
ElemType *elem;//存储空间基址
int length;
int listsize;
}SqList;
函数接口的基本操作如下:
Status InitList(SqList& L);//构造一个空的线性表
Status CreateList(SqList &L, int n) ;//建立一个线性表
Status EmptyList(SqList L) ;//判空
Status DestoryList(SqList L) ;//销毁线性表
tatus RiorElem(SqList L, int cur_e, int &pre_e) ;//cur_e是L的数据元素,且不是第一个,则用pre_e返回它的直接前驱
Status NextElem(SqList L, int cur_e, int &next_e);//cur_e是L的数据元素,且不是最后一个,则用pre_e返回它的直接后继
Status DeleteListSqList &L, int i, int &e) ;//删除第i个元素并用e返回其值
Status ListInsert(SqList &L, int i, int e) ;//在第i个元素之前插入e
Status BubbleSortList(SqList &L);//对链表进行排序
Status MergeList(SqList La, SqList Lb,SqList &L