/* File: dynlist.H Copyright glh 10/12/92 */ #ifndef DYNLISTH #define DYNLISTH #include #include #include typedef enum {false, true} Boolean; // forward declaration for iterator class template class DynListIterator; template class DynList { friend class DynListIterator; protected: int length, size; T* element; public: inline DynList(); inline DynList(const T&); DynList(const DynList&); inline ~DynList(); DynList& operator=(const DynList&); friend ostream& operator<<(ostream&, const DynList&); Boolean Insert(const T&, int); Boolean Append(const T&); Boolean Replace(const T&, int); T& Retrieve(int) const; Boolean Delete(int); inline int Length() const; inline Boolean Empty() const; inline void MakeEmpty(); }; template inline DynList::DynList() {size = 2; element = new T[size]; length = 0;} template inline DynList::DynList(const T& elm) {size = 2; element = new T[size]; element[0]=elm; length=1;} template inline DynList::~DynList() {delete [] element;} template inline int DynList::Length() const {return length;} template inline Boolean DynList::Empty() const {return length == 0 ? true : false;} template inline void DynList::MakeEmpty() {length=0;} template class DynListIterator { private: int current; const DynList* list; public: inline DynListIterator(const DynList&); inline int Reset(); inline int Current() const; inline int operator++(); //prefix inline int operator++(int); //postfix }; template inline DynListIterator::DynListIterator(const DynList& lst) {lst.length==0 ? current=0 : current=1; list = &lst;} template inline int DynListIterator::Current() const {return current;} template inline int DynListIterator::Reset() {return list->length == 0 ? current=0 : current=1;} template inline int DynListIterator::operator++() {return ++current;} template inline int DynListIterator::operator++(int) {return ++current;} #endif