//头文件 include"c1.h"
#include<string.h>
#include<ctype.h>
#include<malloc.h> // malloc()等
#include<limits.h> // INT_MAX等
#include<stdio.h> // EOF(=^Z或F6),NULL
#include<stdlib.h> // atoi()
#include<io.h> // eof()
#include<math.h> // floor(),ceil(),abs()
#include<process.h> // exit()
#include<iostream.h> // cout,cin
// 函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
// #define OVERFLOW -2 因为在math.h中已定义OVERFLOW的值为3,故去掉此行
typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef int Boolean; // Boolean是布尔类型,其值是TRUE或FALSE
//头文件 #include"Sqlist.h"
#ifndef s
#define s
#define LIST_INIT_SIZE 10 // 线性表存储空间的初始分配量
#define LISTINCREMENT 2 // 线性表存储空间的分配增量
typedef int ElemType;
struct SqList
{
ElemType *elem; // 存储空间基址
int length; // 当前长度
int listsize; // 当前分配的存储容量(以sizeof(ElemType)为单位)
};
#enddif s
// 线性表的各种功能的实现 #include"Sqlist.cpp"
// 顺序表示的线性表的基本操作(12个)
#include"c1.h"
#include"定义Sqlist.h"
Status InitList(SqList &L) // 算法2.3: 构造一个空的顺序线性表
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem)
exit(OVERFLOW); // 存储分配失败
L.length=0; // 空表长度为0
L.listsize=LIST_INIT_SIZE; // 初始存储容量
return OK;
}
Status DestroyList(SqList &L) // 操作结果:销毁顺序线性表L
{
free(L.elem);
L.elem=NULL;
L.length=0;
L.listsize=0;
return OK;
}
Status ClearList(SqList &L) // 操作结果:将L重置为空表
{
L.length=0;
return OK;
}
Status ListEmpty(SqList L) // 操作结果:若L为空表,则返回TRUE,否则返回FALSE
{
if(L.length==0)
return TRUE;
else
return FALSE;
}