顺序存储结构
#include<cstdio>
#define Elemtype int
#define MaxSize 50
typedef struct {
Elemtype data[MaxSize];
int length;
}SqList;
bool Insert(SqList &L,int i,Elemtype e)
{
if(i<1 || i>L.length+1)
{
return false;
}
if(L.length >= MaxSize)
{
return false;
}
for(int j=L.length;j>=i;j--)
{
L.data[j] = L.data[j-1];
}
L.data[i] = e;
L.length++;
return true;
}
bool Delete(SqList &L,int i,Elemtype e)
{
if(i<1||i>L.length)
{
return false;
}
e = L.data[i-1];
for(int j=i;j<L.length;j++)
{
L.data[j-1] = L.data[j];
}
L.length--;
return true;
}