首先要确定你想采用线性表的顺序存储结构还是链式存储结构。
以顺序存储结构为例:
#include
#include
#define ERROR 0
#define OK 1
typedef int Status;
typedef int ElemType;//顺序表测试用
const int MaxSize=100; //100只是示例性的数据,可以根据实际问题具体定义
const int Increasement=10;
typedef struct{
ElemType *elem;
int length;
int listsize;
}SeqList;
Status InitList(SeqList &S,int n=MaxSize)
{//初始化线性表
if(n<=0)
n=MaxSize;
S.elem =(ElemType *)malloc(n*sizeof(ElemType));
if(S.elem ==NULL)
exit(ERROR);
S.length =0;
S.listsize =n;
return OK;
}
int ListLength(SeqList &S)
{ //求线性表的长度
return S.length ;
}
void GetElem(SeqList &S,int i,ElemType &e)
{//按位查找,取线性表的第i个元素</