实验目的
1、掌握顺序表中元素的前驱、后续的概念。
2、掌握顺序表的建立、插入元素、删除表中某元素的操作。
3、对顺序表相应算法的时间复杂度进行分析。
4、理解顺序表数据结构的特点(优缺点)。
实验内容和要求
要求实现顺序表的操作集。
函数接口定义
Status InitList_Sq(SqList &L)
Status ListInsert_Sq(SqList &L, int i, ElemType e)
Status ListDelete_Sq(SqList &L,int i, ElemType &e)
Status DestroyList(SqList &L)
Status ListEmpty(SqList L)
SqList结构定义如下:
typedef char ElemType;
typedef int Status;
typedef struct
{
ElemType *elem;
int length;
int listsize;
} SqList;
各个操作函数的定义为:
Status InitList_Sq(SqList &L):创建一个空的线性表L;
Status ListInsert_Sq(SqList &L, int i, ElemType e):在线性表L中第i个位置之前插入新的元素e;
ListDelete_Sq(SqList &L,int i, ElemType &e):在顺序表L中删除第i个元素,并用e返回其值。
Status DestroyList(SqList &L): 销毁顺序表操作。销毁成功,返回OK。
Status ListEmpty(SqList L): 判断顺序表是否是空表。如果顺序表为空,返回1,否则,返回0。
测试程序样例
#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTI