talking is cheap,show me the code;
静态分配顺序表
#include <stdio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 10
typedef int ElemType;
typedef struct{
ElemType data[LIST_INIT_SIZE];
int length;
}SqList;
void InitList(SqList &L){
for(int i=0;i<LIST_INIT_SIZE;i++)
L.data[i]=0;
L.length=0;
}
bool ListInsert(SqList &L,int i,ElemType e){
if(i<1||i>L.length+1)
return false;
if(L.length>=LIST_INIT_SIZE)
return false;
for(int j=L.length;j>=i;j--)
L.data[j]=L.data[j-1];
L.data[i-1]=e;
L.length++;
return true;
}
bool ListDelete(SqList &L,int i,ElemType &e){
if(i<1||i>L.length)
return false;
e=L.data[i-