顺序表类定义:
template<class T>
class SeqList :
{
public:
SeqList(int mSize);
~SeqList()
{
delete[] elements;
}
bool SM_Delete(T x);
private:
int maxLength;
T *elements;
};
template <class T>
SeqList<T>::SeqList(int mSize)
{
maxLength = mSize;
elements = new T[maxLength];
n = ;
}
删除所有特定元素x成员函数:
/*这里提供两种方式,其中一种为了方便测试,作为注释附带*/
template <class T>
bool SeqList<T>::SM_Delete(T x)
{ for (int i = ; i < n; i++)
{
if (elements[i] == x)
/*
for (int j = i+1; j < n; j++)
{
elements[j-1 ] = elements[j];
}
n--;
*/
Delete(i);
}
return true;
/*
for (int i = 0; i < n;i++)
Delete(Search(x));
return true;
*/
}