### Need help implementing deque functions

I have an assignment where I have to implement the member functions for a deque class. I've got most of them, but I'm completely stumped with the second erase function and the insert function. The book says the insert function is similar to the first erase function, and I know the second erase is supposed to delete a range of functions. Can someone help me figure this out?

I also think there might be something wrong with my back() function. I'm getting an assertion failure from my main program.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133`` ``````#include using namespace std; template class DequeIterator; template class Deque { public: typedef DequeIterator iterator; Deque(): vecOne(), vecTwo() { } Deque(const unsigned int size, const T& initial): vecOne(size/2, initial), vecTwo(size-(size/2), initial) { } Deque(const Deque & d): vecOne(d.vecOne), vecTwo(d.vecTwo) { } ~Deque() { } // destructors for vecOne and vecTwo are automatically called // never call a destructor explicitly Deque & operator=(const Deque&d){DequeIterator theDeque;return d=theDeque;} T & operator[](unsigned int); T & front(); T & back(); bool empty() {return vecOne.empty() && vecTwo.empty();} iterator begin() {return iterator(this, 0);} iterator end(){return iterator(this, size());} void erase(const iterator &); void erase(const iterator &, const iterator &); void insert(const iterator &, const T &); int size() {return vecOne.size() + vecTwo.size();} void push_front(const T & value) {vecOne.push_back(value);} void push_back(const T & value) {vecTwo.push_back(value);} void pop_front(); void pop_back(); protected: vector vecOne; vector vecTwo; }; // Your code goes here ... template T & Deque::operator[](unsigned int index) { //return given element for deque int n=vecOne.size(); if(index<=n) { return vecOne[(n-1)-index]; } else { return vecTwo[index-n]; } } template T & Deque::front() { //return first element in deque if(vecOne.empty()) { return vecTwo.front(); } else { return vecOne.back(); } } template T & Deque::back() { if(vecOne.empty()) { return vecTwo.back(); } else { return vecOne.front(); } } template void Deque::erase(const iterator & itr) { int index=itr.index; int n=vecOne.size(); if(index < n) { vecOne.erase(vecOne.begin() + ((n-1)-index)); } else { vecTwo.erase(vecTwo.begin() + (n-index)); } } template void Deque::erase(const iterator &, const iterator &) { //??? } template void Deque::insert(const iterator &, const T &) { //??? } template void Deque::pop_front() { if(vecOne.empty()) { vecTwo.erase(vecTwo.begin()); } else { vecOne.pop_back(); } } template void Deque::pop_back() { if(vecTwo.empty()) { vecOne.pop_back(); } else { vecTwo.pop_back(); } }``````
The vector has insert:

http://www.cplusplus.com/reference/vector/vector/insert/

as well as erasing a range of iterators:

http://www.cplusplus.com/reference/vector/vector/erase/
-> `iterator erase (iterator first, iterator last);`
Topic archived. No new replies allowed.