文档介绍:/*实验1顺序表基本操作
ttinclude ,ziostream. h〃
#include<process. h> /* exit 0 */
/*函数结果状态代码*/
ttdefine TRUE 1
#define FALSE 0
#define OK 1
ttdefine ERROR 0
ttdefine INFEASIBLE -1
ttdefine OVERFLOW -2
typedef int Boolean; /* Boolean是布尔类型,其值是TRUE或FALSE */ typedef int Status;
ttdefine LIST_INIT_SIZE 10 /*线性表存储空间的初始分配量*/
ttdefine LISTINCREMENT 2 /*线性表存储空间的分配增量*/
template <class ElemType> class SeqList (
ElemType *elem; /*存储空间基址*/
int length; /* 当前长度 */
int listsize; //当前分配的存储容量(以sizeof(ElemType)为单位)
public:
SeqList ( int Size = LIST_INIT_SIZE );
^SeqList ( ) ( delete [ ] elem; elem=NULL;length=0;listsize=0; } Status ClearList()
{ /*初始条件:顺序线性表L已存在。操作结果:将L重置为空表*/ length=0; return OK;
}
Status ListEmpty()
{ /*初始条件:顺序线性表L已存在。操作结果:若L为空表,则返回TRUE,否则返 回FALSE */
if (L. length==0) return TRUE;
else
return FALSE;
}
int ListLengthO
{ /*初始条件:顺序线性表L已存在。操作结果:返回L中数据元素个数*/ return length;
}
Status GetElem(int i, ElemType &e)
( /*初始条件:顺序线性表L已存在,IWiWListLength(L) */
/*操作结果:用e返回L中第i个数据元素的值*/
if(i<l||i>length)
exit(ERROR);
e=*(elem+i-l);
return OK;
)
int LocateElem(ElemType e, Status(^compare) (ElemType, ElemType)) const;
Status PriorE1em(E1emType cur_e, ElemType &pre_e);
Status NextElem(ElemType cur_e, ElemType &next_e);
Status Listinsert(int i, ElemType e);
Status ListDelete(int i,ElemType &e);
Status ListTraverse(void(*vi)(ElemType&));
};
template <class ElemTyp