Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C + + Create a subclass of our Array class in a Deque.h file that is templated for any type and that implements the following
C Create a subclass of our Array class in a Deque.h file that is templated for any type and that implements the following methods: readFront: Returns the value of the first element in the array. readBack: Returns the value of the last element in the array. addFront: Inserts a new value at the front of the array. addBack: Inserts a new value at the end of the array. removeFront: Removes the first element of the array. removeBack: Removes the last element of the array. Deques work a lot like a cross breed between a queue and a stack. Use this array class: #ifndef ARRAYH #define ARRAYH #include using namespace std; template class Array protected: TYPE values; int size; int capacity; int startingCapacity; public: Arrayint capacity : size capacitycapacity startingCapacitycapacity values new TYPEcapacity; Array : Array ~Array delete values; int getSize return thissize; TYPE getValues return thisvalues; void resize TYPE temp values; capacity startingCapacity; values new TYPEcapacity; forint i ; i thissize; i valuesi tempi; delete temp; TYPE getint index return valuesindex; void addTYPE value ifthissize thiscapacity thisresize; valuessize value; size; void addTYPE value, int index ifthissize thiscapacity thisresize; forint i size; i index; i valuesi valuesi ; valuesindex value; thissize; void removeint index forint i index; i thissize ; i valuesi valuesi ; thissize; int searchTYPE value forint i ; i thissize; i ifthisvaluesi value return i; return ; friend ostream& operatorostream& os Array& array forint i ; i array.size; i os array.geti; return os; void swapint a int b TYPE temp valuesa; valuesa valuesb; valuesb temp; void bubbleSort int unsorted thissize ; bool sorted false; whilesorted sorted true; forint i ; i unsorted; i ifvaluesi valuesi swapi i ; sorted false; unsorted; void selectionSort int lowestIndex ; forint i ; i thissize ; i lowestIndex i; forint j i ; j thissize; j ifvaluesj valueslowestIndex lowestIndex j; iflowestIndex i swapi lowestIndex; void insertionSort TYPE heldValue; int gap ; forint i ; i size; i heldValue valuesi; gap i ; whilegap && valuesgap heldValue valuesgap valuesgap; gap; valuesgap heldValue; void shuffle forint i ; i thissize; i swapi rand thissize; void bogoSort whilethisisSorted thisshuffle; ; #endif
C Create a subclass of our Array class in a Deque.h file that is templated for any type and that implements the following methods:
readFront: Returns the value of the first element in the array.
readBack: Returns the value of the last element in the array.
addFront: Inserts a new value at the front of the array.
addBack: Inserts a new value at the end of the array.
removeFront: Removes the first element of the array.
removeBack: Removes the last element of the array.
Deques work a lot like a cross breed between a queue and a stack.
Use this array class:
#ifndef ARRAYH
#define ARRAYH
#include
using namespace std;
template
class Array
protected:
TYPE values;
int size;
int capacity;
int startingCapacity;
public:
Arrayint capacity :
size
capacitycapacity
startingCapacitycapacity
values new TYPEcapacity;
Array : Array
~Array
delete values;
int getSize
return thissize;
TYPE getValues
return thisvalues;
void resize
TYPE temp values;
capacity startingCapacity;
values new TYPEcapacity;
forint i ; i thissize; i
valuesi tempi;
delete temp;
TYPE getint index
return valuesindex;
void addTYPE value
ifthissize thiscapacity
thisresize;
valuessize value;
size;
void addTYPE value, int index
ifthissize thiscapacity
thisresize;
forint i size; i index; i
valuesi valuesi ;
valuesindex value;
thissize;
void removeint index
forint i index; i thissize ; i
valuesi valuesi ;
thissize;
int searchTYPE value
forint i ; i thissize; i
ifthisvaluesi value
return i;
return ;
friend ostream& operatorostream& os Array& array
forint i ; i array.size; i
os array.geti;
return os;
void swapint a int b
TYPE temp valuesa;
valuesa valuesb;
valuesb temp;
void bubbleSort
int unsorted thissize ;
bool sorted false;
whilesorted
sorted true;
forint i ; i unsorted; i
ifvaluesi valuesi
swapi i ;
sorted false;
unsorted;
void selectionSort
int lowestIndex ;
forint i ; i thissize ; i
lowestIndex i;
forint j i ; j thissize; j
ifvaluesj valueslowestIndex
lowestIndex j;
iflowestIndex i
swapi lowestIndex;
void insertionSort
TYPE heldValue;
int gap ;
forint i ; i size; i
heldValue valuesi;
gap i ;
whilegap && valuesgap heldValue
valuesgap valuesgap;
gap;
valuesgap heldValue;
void shuffle
forint i ; i thissize; i
swapi rand thissize;
void bogoSort
whilethisisSorted
thisshuffle;
;
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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