首先进行头文件的使用、宏定义以及使用typedef创建别名:
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREAMENT 10
typedef float ElemType;
typedef int Status;
typedef struct
{
ElemType *elem; /* 指向线性表占用的数组空间。*/
int length; /*线性表的长度*/
int listsize;
} SqList;
五个包文件:
1.对空表的创建:
//创建空表
Status initlist_sq(SqList &L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
2.插入:
Status listinsert(SqList &L,int i,ElemType e)
{
int j;
if(i<1||i>L.length+1)
return ERROR;
if(L.length==L.listsize)
return ERROR;
for(j=L.length-1;j>=i-1;j--)
{
L.elem[j+1]=L.elem[j];
}
L.elem[i-1]=e;
++L.length;
return OK;
}
3.删除:
//删除
Status listdelete(SqList &L,int i)
/