#ifndef ___DOUBLE_LINKED_LIST__ #define ___DOUBLE_LINKED_LIST__ template class dnode { public: T data; dnode* prev, * next; dnode() { prev = next = NULL; } dnode(const T elem) { data = elem; prev = next = NULL; } }; template class Itr { private: dnode* current; public: Itr() { current = NULL; } Itr(dnode* ptr) { current = ptr; } Itr& operator++(); //pre-increment ++i Itr operator++(int); //post-increment i++ Itr& operator--(); //pre-decrement --i Itr operator--(int); //post-decrement i-- T operator*() const { return current->data; }; T& operator*() { return current->data; }; const dnode* operator->() const { return current; }; dnode* operator->() { return current; }; }; template Itr& Itr::operator++() //pre-increment ++i { if (current != NULL) current = current->next; //Itr rlt(current); //return rlt; return *this; } template Itr Itr::operator++(int) //post-increment i++ { Itr rlt(current); if (current != NULL) current = current->next; return rlt; } template Itr& Itr::operator--() //pre-decrement --i { if (current != NULL) current = current->prev; //Itr rlt(current); //return rlt; return *this; } template Itr Itr::operator--(int) //post-decrement i-- { Itr rlt(current); if (current != NULL) current = current->prev; return rlt; } template class DList { private: dnode* front, * rear; public: DList(); ~DList(); bool isEmpty() const; bool isFull() const; const Iter operator[](int) const; Iter& operator[](int); const Iter find(const T &elem) const; Iter& find(const T & elem); const Itr begin() const { return Itr(front); } Itr& begin() const { return Itr(front); } const Itr end() const { return Itr(rear); } Itr& end() const { return Itr(rear); } void insertBeforeNode(const T& elem, Iter iterator); void insertAfterNode(const T& elem, Iter iterator); void remove(Itr iterator); }; #endif