数据结构第 一 、 二 次 上 机 :#include #include #include #define TRUE 1 #define FALSE 0 #define OK 1#define ERROR 0#define INFEASIBLE -1 #define OVERFLOW -2#define list_init_size 100//线性表存储空间的初始分配量#define LISTINCREMENT 10//线性表存储空间的分配增量typedef int Status; typedef intElemType;typedef struct{ElemType *elem;//存储空间基址int length;//当前长度intlistsize;//当前分配的存储容量(以sizeof(ElemType)为单位) }SqList;Status InitList_Sq(SqList&L){//构造一个空的线性表*LL
elem=(ElemType)malloc(list_init_size*sizeof(ElemType));if(
elem)exit(OVERFLOW);// 存 储 分 配 失 败L
length =0;// 空 表 长 度 为 0L
listsize =list_init_size;// 初 始 存 储 容 量returnOK; }//Initlist_SqStatus ListInsert_Sq(SqList&L,inti,ElemType e){//在顺序线性表 L 中第 i 个位置之前插入新的元素 e,//i的 合 法 值 为1=q;--p)*(p+1)=*p;// 插 入 位 置 及 之 后 的 元 素 右 移*q=e;//插入 e++L
length//表长增1return OK; }//ListInsert_SqStatusList