一、声明与结构体定义:
#include <stdio.h>
#define Initsize 10
#define false 0
#define ture 1
#define Elemtype int
typedef struct
{
Elemtype* data;
int Maxsize;
int length;
}Sqlist;
二、初始化顺序表(用malloc申请动态内存空间):
void InitList(Sqlist &L)
{
L.data = (int*)malloc(InitSize * sizeof(int));
L.length = 0;
L.Maxsize = InitSize;
}
三、增加动态顺序表空间
void IncreaseSize(Sqlist& L, int len)
{
int* p = L.data;
L.data = (Elemtype*)malloc((L.Maxsize + len) * sizeof(Elemtype));
for (int i = 0; i < L.length; i++)
L.data[i] = p[i];
L.Maxsize = L.Maxsize + len;
}