动态顺序表:
//动态顺序表
#include<stdio.h>
#include<stdlib.h>
#define LIST_SIZE 100 //顺序表存储空间的初始分配量
typedef int ElementType;
typedef struct SqList* List;
struct SqList{
ElementType* elem;//存储空间的基址
int length;//顺序表的当前长度
int capacity;//当前为顺序表分配的存储容量
//第i个数据元素是L->elem[i-1]
};
//创建一个空的顺序表表
int InitList(List L){
L->elem=(ElementType*)malloc(LIST_SIZE*sizeof(ElementType));
if(!L->elem)
return 0;//表示内存分配失败,程序异常退出
L->length=0;
L->capacity=LIST_SIZE;
return 1;
}
//顺序表的插入
int ListInsert(List L,int i,ElementType X){
//在顺序表L中第i个位置插入新元素X
ElementType* newbase;
if(i<1||i>L->length+1)//插入的位置不合法
return 0;
if(L->length>=L->capacity){
//如果顺序表当前存储空间已满,则重新分配内存
newbase=(ElementType*)realloc(L->elem,(2*L->capacity)*sizeof(ElementType));
if(!</