#include<stdio.h> //程序的头文件
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#define OK 1 // 函数返回值
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define NULL 0
#define LIST_INIT_SIZE 100 //顺序表的初始大小
#define LISTINCREMENT 10 //顺序表的递增大小
typedef int Status; //返回状态类型
typedef char ElemType; //元素类型
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList; //结点类型 指针类型
Status InitList(SqList &l)
{
//初始化顺序表
l.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!l.elem) exit(OVERFLOW);
l.length=0;
l.listsize=LIST_INIT_SIZE;
return OK;
}
int ListLength(SqList l)
{
//求顺序表的长度
return(l.length);
}
Status ListInsert_Sq(SqList &L,int i, ElemType e)
{
//在顺序表 L 的第 i 个位置前插入元素 e,i 的合法值为 1..L.length+1
if(i<1||i>L.length+1)
return ERROR;
if(L.length>=L.listsize)
{
ElemType*newbase=(ElemType
*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));
评论0