#ifndef ALT_LINKED_DEQUE_H #define ALT_LINKED_DEQUE_H #include // ensure that NULL is defined /** * An implementation of a deque using a doubly-linked list WITHOUT sentinels. */ template class AltLinkedDeque { public: AltLinkedDeque(); // construct empty deque int size() const; // number of items in deque bool empty() const; // is the deque empty? const Object& front() const; // access the front element const Object& back() const; // access the back element void push_front(const Object& e); // add element to the front of the deque void push_back(const Object& e); // add element to the back of the deque void pop_front(); // remove the front item from the deque void pop_back(); // remove the back item from the deque // housekeeping functions AltLinkedDeque(const AltLinkedDeque& other); ~AltLinkedDeque(); AltLinkedDeque& operator=(const AltLinkedDeque& other); protected: struct Node { Object elem; // element Node* prev; // prev pointer Node* next; // next pointer Node(const Object& e = Object(), Node* prv = NULL, Node* nxt = NULL) : elem(e), prev(prv), next(nxt) { } // constructor }; private: // instance variables Node* head; // node with first deque element Node* tail; // node with last deque element int n; // number of items in deque // utilities for housekeeping void removeAll(); // utility for housekeeping void copyFrom(const AltLinkedDeque& other); // utility for housekeeping }; // end of AltLinkedDeque class #include "AltLinkedDeque.tcc" #endif