#define TRUE 1
#define FALSE 1
#define ERROR 0
#define MAX_SIZE 100
#define OK 1
/**顺序存储
*
* */
class ShunList{
typedef struct{
int data;
}ElemType;
typedef struct{
ElemType *data;
int length;
}SqList;
static int initList(SqList &L){
L.data=new ElemType[MAX_SIZE];
if (!L.data) exit(OVERFLOW);
return TRUE;
}
int GetElem(SqList L,int i,ElemType &e){
if (i<1||i>L.length) return ERROR;
e=L.data[i-1];
return OK;
}
static int LOC(SqList L,ElemType e){
for (int i = 0; i < L.length; ++i) {
// if (L.data[i] == e){
// return i+1;
// }
}
return 0;
}
static int ListInsert_Sq(SqList &L,int i,ElemType e){
if (i<1||i>L.length) return ERROR;
if (L.length==MAX_SIZE)return ERROR;
for (int j = L.length-1; j >= i-1 ; j--) {
L.data[j+1]=L.data[j];
}
L.data[i-1]=e;
L.length++;
return OK;
}
int ListDelete(SqList &L,int i,ElemType &e){
/**时间复杂度
* i=1 2 3 ... n
* n-1 n-2 n-3 ... n-i
* (n-1)/2
* O(n)
* */
if (i<1||i>L.length) exit(ERROR);
e=L.data[i-1];
for (int j = i-1; j < L.length-1; ++j) {
L.data[j]=L.data[j+1];
}
L.length--;
return OK;
}
//线性表合并 两个集合求并集 A ∪ B
void union_A_B(SqList &La,SqList Lb){
}
};
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。