// 顺序表的模板实现 // By KiRa 07/08/23 参考数据结构算法与应用-C++语言描述 /**//* Length = 0 IsEmpty = 1 List is 2 6 IsEmpty = 0 First element is 2 Length = 2 Deleted element is 2 List is 6 */ #include <iostream> #include <new> using namespace std; class NoMem ...{ public: NoMem() ...{} }; void my_new_handler() ...{ throw NoMem(); }; new_handler Old_Handler_ = set_new_handler(my_new_handler); class OutOfBounds ...{ public: OutOfBounds() ...{} }; template<class T> class LinearList...{ public: LinearList(int MaxListSize = 30); ~LinearList() ...{delete [] element;} bool IsEmpty() const ...{return length ==0;} int Length() const ...{return length;} bool Find(int k, T& x) const; int Search(const T& x) const; LinearList<T>& Delete(int k, T& x); LinearList<T>& Insert(int k, const T& x); void Output(ostream& out) const; private: int length; int MaxSize; T *element; }; |