#include // defines std::runtime_error /* Standard constructor creates an empty deque. */ template AltLinkedDeque::AltLinkedDeque() : head(NULL), tail(NULL), n(0) { } /* Return the number of objects in the deque. */ template int AltLinkedDeque::size() const { return n; } /* Determine if the deque is currently empty. */ template bool AltLinkedDeque::empty() const { return n == 0; } /* Return a const reference to the front object in the deque. */ template const Object& AltLinkedDeque::front() const { if (empty()) throw std::runtime_error("Access to empty deque"); return head->elem; } /* Return a const reference to the back object in the deque. */ template const Object& AltLinkedDeque::back() const { if (empty()) throw std::runtime_error("Access to empty deque"); return tail->elem; } /* Insert an object at the front of the deque. */ template void AltLinkedDeque::push_front(const Object& e) { // YOUR CODE HERE } /* Remove the back object from the deque. */ template void AltLinkedDeque::pop_back() { // YOUR CODE HERE } /* Insert an object at the back of the deque. */ template void AltLinkedDeque::push_back(const Object& e) { // would be symmetric to push_front } /* Remove the front object from the deque. */ template void AltLinkedDeque::pop_front() { // would be symmetric to pop_back } // housekeeping functions remain template void AltLinkedDeque::removeAll() { // remove entire deque contents while (!empty()) pop_back(); // for simplicity, reuse existing method } template void AltLinkedDeque::copyFrom(const AltLinkedDeque& other) { Node* walk(other.head); // the front node while (walk != NULL) { push_back(walk->elem); walk = walk->next; } } /* Copy constructor */ template AltLinkedDeque::AltLinkedDeque(const AltLinkedDeque& other) : head(NULL), tail(NULL), n(0) { copyFrom(other); } /* Destructor */ template AltLinkedDeque::~AltLinkedDeque() { removeAll(); } /* Assignment operator */ template AltLinkedDeque& AltLinkedDeque::operator=(const AltLinkedDeque& other) { if (this != &other) { // avoid self copy (x = x) removeAll(); // remove old contents copyFrom(other); // copy new contents } return *this; }