线性表的顺序存储结构称作顺序表,其基本思想是用一段地址连续的存储单元依次存储线性表中的数据元素。其中数组下标与数据元素的序号是一一对应的。一般需要分配固定长度的数组空间存储顺序表。
一、顺序表的构造
template <typename T>
class Seqlist{
public:
Seqlist();
Seqlist(T a[], int n);
int Length();
T Get(int i);
int Location(T x);
void Insert(int i, T x);
T Delete(int i);
int Empty();
void PrintList();
private:
T data[Maxn];
int length;
};
-
构造空顺序表
template<typename T> void Seqline<T>::SeqLine(){ T data[MAXN]; length=0; }
-
构造非空顺序表
template <typename T> Seqlist<T>::Seqlist(T a[], int n){ if (n > Maxn) throw "参数非法"; for (int i = 0; i < n; ++i){ data[i] = a[i]; } length = n; }
- 析构函数
顺序表为静态存储分配,在顺序表变量退出作