1 //函数状态代码 2 #define TURE 1 3 #define FALSE 0 4 #define OK 1 5 #define ERROR 0 6 #define INFEASIBLE -1 7 #define OVERFLOW -2 8 #define Maxsize 100 9 //Status 是函数的类型,其值是函数结果的状态代码 10 typedef int Status; 11 typedef char ElemType; 12 typedef struct{ 13 ElemType *elem; 14 int length; 15 }Sqlist; 16 //线性表L的初始化 17 Sqlist L; 18 Status InitList_Sq(Sqlist &L){ //构造一个空的顺序表 19 L.elem=new ElemType[Maxsize]; //为顺序表分配空间 20 if(!L.elem) exit(OVERFLOW);//存储分配失败 21 L.length=0; //空表长度为0 22 return OK; 23 } 24 //销毁线性表L 25 void DestroyList(Sqlist &L){ 26 if(L.elem) delete L.elem;//释放存储空间 27 } 28 //清空线性表L 29 void ClearList(Sqlist &L){ 30 L.length=0;//将线性表的长度置为0 31 } 32 //求线性表的长度 33 int GetLength(Sqlist L){ 34 return (L.length); 35 } 36 //判断线性表长度是否为空 37 38