(1)初始化顺序表;
(2)给定一个整型数据元素,将此元素插入到顺序表的第i个位置;
(3)删除顺序表中第i个位置的元素,利用e返回被删除的元素。
/*
(1)初始化顺序表;
(2)给定一个整型数据元素,将此元素插入到顺序表的第i个位置;
(3)删除顺序表中第i个位置的元素,利用e返回被删除的元素。
*/
#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
//----- 顺序表的顺序存储表示 -----
#define LIST_INIT_SIZE 100 // 存储空间的初始分配量
#define LISTINCREMENT 10 // 存储空间的分配增量
typedef struct {
ElemType *elem; // 存储空间的基址
int length; // 表长
int size;// 存储容量
int increment; // 扩容时,增加的存储容量
} SqList; //顺序表
// 构造一个顺序表
Status InitSqlist(SqList &L){
L.elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem) exit (OVERFLOW);
L.length = 0;
L.size = LIST_INIT_SIZE;
L.increment = LISTINCREMENT;
return OK;
}
// 判顺序表是否为空表
Status ListEmpty(SqList L){
if (L.length==0) return OK;
else re