/*
*函数结构状态代码
*/
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBILE -1
#define OVERFLOW -2
/*
*Status 是函数的类型,其值是函数结果状态代码
*/
typedef int Status;
typedef char ElemType;
创建链表
Status LnitList_Sq(SqList &L){
L.elem=new Status[MAXSIZE];
if(!L.elem){
exit(OVERFLOW);
}
L.length=0;
return OK;
}
销毁线性表
void DestroyList(SqList &L){
if(L.elem)
delete L.elem;
}
清空线性表
void ClearList(SqList &L){
L.ength=0;
}
顺序表取值
int GetElem(SqList L,int i,ElemType &e){
if(i<1||i>L.length)
return ERROR;
e=L.elem[i-1];
return OK;
}
顺序表查找
int LocateElem(SqList L,ElemType e){
for(int i=0;i<L.length;i++){
if(L.elem[i]==e)
return [i+1]
}
return 0;
}
顺序表的插入
Status ListInser_Sq(SqList &L.int i,ElemType e){
if(i<1||i>L.length) return ERROR;
if(L.length==MAXSIZE) return ERROR;
for(j=L.length-1;j>=-1;j--)
L.elem[j+1]=L.elem[j];
L.elem[i-1]=e;
L.length++;
return OK;
}
顺序表的删除
Ststus ListDelete_Sq(SqList &L,int i){
if(i<1||i>L.length) return ERROR;
for(j=i;j<=L.length-1;j++)
L.elem[j-1]=L.elem[j];
L.length--;
return Ok;
}
顺序表优缺点:
优点
缺点
原文:https://www.cnblogs.com/hunhun5201314/p/15169696.html