这是最简单的顺序表,顺序表中的元素都存储在数组T *data中
const int defaultSize = 100;
template <class T>
class LinearList
{
protected:
T *data;
int maxSize;
int last;
void reSize(int newSize);//改变数组的大小
public:
LinearList(int sz = defaultSize);
LinearList(LinearList<T> &L);
~LinearList()
{
delete[]data;
}
int Size()const
{
return maxSize;
}
int Length()const
{
return last + 1;
}
int Search(T &x)const;
int Locate(int i)const;
bool getData(int i, T &x)const
{
if(i > 0 && i <= last + 1)
{
x = data[i + 1];
return true;
}
else return false;
}
void setData(int i, T &x)const
{
if(i > 0 && i <= last + 1) data[i - 1] = x;
}
bool Insert(int i, T &x)const;
bool Remove(int i, T &x)