this is my Deque pop_front pop_back implementation And this is the test program
ID: 3864666 • Letter: T
Question
this is my Deque pop_front pop_back implementation
And this is the test program
Modify your Deque implementation to improve pop front0 and pop back0 For pop front if vecOne is empty, first half of the elements from vecTwo is moved to vecOne, then pop back0 on vecOne is called. For pop back0 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. Hand in printouts of your new Deque.h implementation, the above test program, and the typescript of cmpile and run of the programExplanation / Answer
template <class T>
void Deque <T>::pop_front()
{
if (vecOne.empty() && vecTwo.empty()) {
return;
}
if (vecOne.empty()) {
if (vecTwo.size() == 1) {
vecTwo.pop_back();
} else {
int i = (vecTwo.size()-1)/2;
if(vecTwo.size() % 2 != 0 ) {
vecOne.push_back(vecTwo[i];
--i;
}
While(i != 0) {
vecOne.push_back(vecTwo[i]);
vecTwo[i] = vecTwo.back();
vecTwo.pop_back();
}
if(vecTwo.size() % 2 != 0 ) {
vexTwo.pop_back();
}
vecOne.pop_back();
}
} else {
vecOne.pop_back();
}
}
Implementation of pop_back
template <class T>
void Deque <T>::pop_back()
{
if (vecOne.empty() && vecTwo.empty()) {
return;
}
if (vecTwo.empty()) {
if (vecOne.size() == 1) {
vecOne.pop_back();
} else {
int i = (vecOne.size()-1)/2;
if(vecOne.size() % 2 != 0 ) {
vecTwo.push_back(vecOne[i];
--i;
}
While(i != 0) {
vecTwo.push_back(vecOne[i]);
vecOne[i] = vecOne.back();
vecOne.pop_back();
}
if(vecOne.size() % 2 != 0 ) {
vecOne.pop_back();
}
vecTwo.pop_back();
}
} else {
vecTwo.pop_back();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.