// Doubly Linked List // // Douglas Thrift // // $Id$ #ifndef _DoublyLinkedList_hpp_ #define _DoublyLinkedList_hpp_ #include "NullNode.hpp" #include "Iterator.hpp" template class DoublyLinkedList { private: NullNode front; NullNode back; public: DoublyLinkedList() { front.setNext(&back); back.setPrevious(&front); } ~DoublyLinkedList() { while (front.getNext() != &back) front.removeNext(); } void addFront(const Type& value) { front.addNext(value); } void addBack(const Type& value) { back.addPrevious(value); } bool contains(const Type& value); void removeFirst(const Type& value); void removeLast(const Type& value); Iterator iterator(void) { return Iterator(&front, &back); } void accept(Visitor* visitor); }; template bool DoublyLinkedList::contains(const Type& value) { return front.contains(value, dynamic_cast*>(&back), true); } template void DoublyLinkedList::removeFirst(const Type& value) { front.remove(value, dynamic_cast*>(&back), true); } template void DoublyLinkedList::removeLast(const Type& value) { back.remove(value, dynamic_cast*>(&front), false); } template void DoublyLinkedList::accept(Visitor* visitor) { front.accept(visitor, dynamic_cast*>(&back), true); } #endif // _DoublyLinkedList_hpp_