Question
Modify your Deque implementation to improve pop_front() and pop_back(). For pop_front() if vecOne is empty, first half of the elements from vecTwo is moved to
Modify your Deque implementation to improve pop_front() and pop_back(). For pop_front() if vecOne is empty, first half of the elements from vecTwo is moved to vecOne, then pop_back() on vecOne is called. For pop_back() if vecTwo is empty, first half of the elements from vecOne is moved to vecTwo, then pop_back on vecTwo is called. This test program should work correctly with your new implementation.
__________________________________________________________________________________________________________________
My Deque Class
___________________________________________________________________________________________________________________
#ifndef DEQUE_H #define DEQUE_H
#include
using namespace std;
template
template
Deque(): vecOne(), vecTwo() { } Deque(const unsigned int size, const T & initial): vecOne(size/2, initial), vecTwo(size-(size/2), initial) { } Deque(const Deque
T & operator[](unsigned int); T & front(); T & back(); bool empty(); iterator begin(); iterator end(); //void erase(const iterator &); //void erase(const iterator &, const iterator &); //void insert(const iterator &, const T &); int size(); void push_front(const T & value); void push_back(const T & value); void pop_front(); void pop_back();
protected: vector
template
template
template
template
template
template
template
template
template
template
template
template
template
public: DequeIterator(): theDeque(0), index(0) { } DequeIterator(Deque
T & operator*(); iterator & operator++(); iterator operator++(int); iterator & operator--(); iterator operator--(int); bool operator==(const iterator & r); bool operator!=(const iterator & r); //bool operator<(const iterator & r); //T & operator[](unsigned int i); iterator operator=(const iterator & r); iterator operator+(unsigned i); iterator operator-(unsigned i);
protected: Deque
template
template
return *this; } // operator++ (pre-increment)
template
return temp; } // operator++ (post-increment)
template
template
template
template
template
template
template
#endif
___________________________________________________________________________________________
Test Program
____________________________________________________________________________________________
#include#include "Deque.h" using namespace std; main() { Deque d; d.push_front(1); d.push_front(2); d.push_front(3); d.push_back(50); d.push_back(20); // 3 2 1 50 20 d.pop_back(); d.pop_back(); d.pop_back(); // 3 2 Deque ::iterator i; for (i = d.begin(); i != d.end(); ++i) cout << *i << " "; cout << endl; d.push_back(60); d.push_back(70); // 3 2 60 70 for (i = d.begin(); i != d.end(); ++i) cout << *i << " "; cout << endl; d.pop_front(); d.pop_front(); d.pop_front(); // 70 for (i = d.begin(); i != d.end(); ++i) cout << *i << " "; cout << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started