#include
#include
#include //* EOF(=^Z或F6),NULL /
#include // atoi() /
#include // floor(),ceil(),abs() /
using namespace std;
// 函数结果状态代码 */
#define LIST_INIT_SIZE 100 //线性表的存储空间初始量
#define LISTINCREMENT 10 //线性表的存储空间分配增量
#define OK 1
#define ERROR 0
typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef int ElemType;
typedef struct{
ElemType * elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList &L){
//采用线性表的动态分配顺序存储结构
L.elem =(ElemType *)malloc (LIST_INIT_SIZE *sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);//存储分配失败
L.length=0;//空表长度为0
L.listsize= LIST_INIT_SIZE;//初始存储容量
return OK;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e){
//在顺序线性表L中第i个位置之前插入新得元素e
//i的合法位置是1<=i<=ListLength_Sq(L)+1
if(i<1||i>L.length+1) return ERROR;//i的位置不合法
if(L.length>=L.listsize){/*当前存储空间已满,增加分配*/
L.elem =(ElemType*)realloc(L.elem,L.listsize+LISTINCREMENT*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);//存储分配失败
L.listsize+=LISTINCREMENT;
}
for(int p=L.length;p>=i;p--)
L.elem[p]=L.elem[p-1];//插入位置及之后的元素右移
L.elem[i-1]=e;//插入e
++L.length;//表长加1
return OK;
}
Status ListDelete_Sq(SqList &L,int i,ElemType &e){
//在顺序线性表L中删除第i位元素e
//i的合法位置是1<=i<=ListLength_Sq(L)
if(i<1||i>L.length) return ERROR;//i值不合法
e=L.elem[i-1];
for(int p=i-1;i<L.length-1;p++)
L.elem[p]=L.elem[p+1];
L.elem[L.length-1]=0;//原来最后一项值改为0
L.length--;
}
int main()
{
return 0;
}
//To be continue…