自己把顺序表用C语言写了出来,并小试牛刀,做了一题,将La与Lb合并。
#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_INST_SIZE 5
#define LISTINCREMENT 1
typedef int Status;
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
} sql;
static ElemType element;
/*函数名:InitList()
参数:sql L
初始条件:无
功能:构造一个空线性表
返回值:存储分配失败:OVERFLOW
存储分配成功:OK*/
Status InitList(sql &L)
{
if((L.elem = (ElemType*)malloc(sizeof(ElemType)* LIST_INST_SIZE)) == NULL)
return OVERFLOW;
else
{
L.length = 0;
L.listsize = LIST_INST_SIZE;
return OK;
}
}
/*函数名:DestroyList()
参数: sql L
初始条件:线性表L已存在
功能:销毁线性表
返回值:L.elem == NULL:ERRor
L.elem != NUll:OK*/
Status DestroyList(sql &L)
{
if(L.elem == NULL)
return ERROR;
else
{
free(L.elem);
return OK;
}
}
/*函数名:ClearList()
参数:sql L&#x