Question
Help with finishing Header file in C++. Here is the criteria You are given a partial implementation of a mini-deque class. minideque is a templated
Help with finishing Header file in C++.
Here is the criteria
You are given a partial implementation of a mini-deque class. minideque
HERE ARE THE TWO FILES DO NOT CHANGE MAIN.CPP
Minideque.h
//
// minideque.h
// minidequeproject
//
#ifndef minideque_h
#define minideque_h
#include
#include
#include
#include
#include
template
class minideque {
private:
std::vector
std::vector
public:
minideque() = default; // do not change, C++ defaults are ok
minideque(const minideque
minideque& operator=(const minideque
~minideque() = default;
size_t size() const; // TODO
size_t fronthalfsize() const; // TODO
size_t backhalfsize() const; // TODO
bool empty() const; // TODO
// balance queue across both vectors if pop_front/back is requested on an empty vector
// e.g., minideque has this: | ABCDEFG
// after pop_front BCD | EFG (A discarded)
// symmetric logic for converse case: ABCDEFG | ===> ABC | DEF (G discarded) after pop_back
void pop_front(); // TODO
void pop_back(); // TODO
void push_front(const T& value); // TODO
void push_back(const T& value); // TODO
const T& front() const; // TODO
const T& back() const; // TODO
T& front(); // TODO
T& back(); // TODO
const T& operator[](size_t index) const; // TODO
T& operator[](size_t index); // TODO
void clear(); // TODO
friend std::ostream& operator<<(std::ostream& os, const minideque
if (dq.empty()) { return os << "minideque is empty"; }
dq.printFronthalf(os);
os << "| ";
dq.printBackhalf(os);
os << ", front:" << dq.front() << ", back:" << dq.back() << ", size:" << dq.size();
return os;
}
void printFronthalf(std::ostream& os=std::cout) const { // do not change
if (empty()) { std::cout << "fronthalf vector is empty"; }
for (typename std::vector
crit != fronthalf_.crend(); ++crit) {
os << *crit << " ";
}
}
void printBackhalf(std::ostream& os=std::cout) const { // do not change
if (empty()) { os << "backhalf vector is empty"; }
for (typename std::vector
cit != backhalf_.cend(); ++cit) {
os << *cit << " ";
}
}
};
#endif /* minideque_h */
MAIN.CPP
//
// minideque_project_main.cpp
// minideque_project
//
//
#include
#include "minideque.h"
template
bool testAnswer(const std::string& nameOfTest, const T& received, const T& expected);
size_t testsPassed = 0;
size_t testsFailed = 0;
void test_minideque() {
minideque
dq.push_back(9);
testAnswer("dq[0] == dq.front()", dq[0] == dq.front(), true);
testAnswer("dq[0] == 9", dq[0], 9);
dq.push_front(1);
testAnswer("dq.front() == 1", dq.front(), 1);
testAnswer("dq.back() == 9", dq.back(), 9);
std::vector
std::vector
for (auto el : valuesfront) {
dq.push_front(el);
testAnswer("dq.front() == dq.push_front(el)", dq.front(), el);
}
for (auto el : valuesback) {
dq.push_back(el);
testAnswer("dq.back() == dq.push_back(el)", dq.back(), el);
}
int value = 9999;
dq[0] = value;
testAnswer("assign to array index", dq[0], value);
testAnswer("read from array index", dq[0], value);
std::cout << " clearing the minideque... ";
std::cout << "NOTE: the minideque keeps REBALANCING the front/back to have similar # entries ";
while (!dq.empty()) {
dq.pop_front();
std::cout << "dq.pop_front() ==> " << dq << " ";
if (!dq.empty()) {
if (dq.front() == 10 || dq.front() == 16) {
testAnswer("rebalancing fronthalf and backhalf vectors",
dq.fronthalfsize(), dq.backhalfsize());
}
}
}
std::cout << " Passed: " << testsPassed << " out of: " << testsPassed + testsFailed
<< " total tests. ";
}
template
bool testAnswer(const std::string& nameOfTest, const T& received, const T& expected) {
if (received == expected) {
std::cout << "PASSED " << nameOfTest
<< ": expected and received " << received << std::endl;
++testsPassed;
return true;
}
std::cout << "FAILED " << nameOfTest
<< ": expected " << expected << " but received " << received << std::endl;
++testsFailed;
return false;
}
int main(int argc, const char * argv[]) {
test_minideque();
std::cout << " \t\t...done. ";
return 0;
}
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