//文件名:List.c
//函数的头文件
#include <stdio.h>
#include <stdlib.h>
//函数结果状态码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100//线性表存储空间的初始分配量
#define LISTINCREMENT 10//线性表存储空间的分配增量
//Status是函数的类型,其值是函数结果的状态码
//typedef int Status;
//定义数据类型
typedef int ElemType;
typedef struct{
ElemType *elem;
int length;
int listsize;
} SqList;
int InitList_Sq(SqList *);
//测试主函数
int main()
{
SqList L;
int i;
InitList_Sq(&L);
for(i=0;i<LIST_INIT_SIZE;i++)
{
(L.elem)[i]=i+1;
printf("L的elem[%d]的值为:%d/n",i,(L.elem)[i]);
L.length++;
}
printf("L的长度为:%d/n",L.length);
getch();
return 0;
}
int InitList_Sq( SqList *L){
//构造一个空的线性表L
L->elem=(ElemType *) malloc (LIST_INIT_SIZE*sizeof(ElemType));
//L.elem=new ElemType [LIST_INIT_SIZE*sizeof(ElemType)];
if(L->elem==NULL)
exit(OVERFLOW);
else
{
L->length=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}
}