Question: / / ABQ.h #include using namespace std; template class ABQ { private: static double scale; unsigned int size; unsigned int capacity; T * data; void

// ABQ.h
#include
using namespace std;
template
class ABQ {
private:
static double scale;
unsigned int size;
unsigned int capacity;
T* data;
void resize(double scale);
public:
ABQ();
ABQ(int capacity);
ABQ(const ABQ& d);
ABQ& operator=(const ABQ& d);
~ABQ();
void enqueue(T data);
T dequeue();
T peek();
unsigned int getSize();
unsigned int getMaxCapacity();
T* getData();
};
template
double ABQ::scale =2.0;
template
ABQ::ABQ(){
capacity =1;
size =0;
data = new T[capacity];
}
template
ABQ::ABQ(int capacity){
this->capacity = capacity;
size =0;
data = new T[this->capacity];
}
template
ABQ::ABQ(const ABQ &d){
capacity = d.capacity;
size = d.size;
data = new T[capacity];
for (int i =0; i size; i++)
data[i]= d.data[i];
}
template
ABQ& ABQ::operator=(const ABQ& d){
if (this != &d){
delete[] data;
capacity = d.capacity;
size = d.size;
data = new T[capacity];
for (int i =0; i size; i++)
data[i]= d.data[i];
}
return *this;
}
template
ABQ::~ABQ(){
delete[] data;
}
template
void ABQ::enqueue(T data){
if (size == capacity){
resize(scale);
}
this->data[size]= data;
size++;
}
template
T ABQ::dequeue(){
if (size ==0)
throw runtime_error("Unable dequeue from an empty queue");
T item = data[0];
for (size_t i =0; i size -1; i++)
data[i]= data[i +1];
size--;
if (capacity >1){
if ((((double)size)/ capacity)((double)1/ scale))
resize((double)1/ scale);
}
return item;
}
template
T ABQ::peek(){
if (size ==0)
throw runtime_error("Unable to dequeue from an empty queue");
return data[0];
}
template
unsigned int ABQ::getSize(){
return size;
}
template
unsigned int ABQ::getMaxCapacity(){
return capacity;
}
template
T* ABQ::getData(){
return data;
}
template
void ABQ::resize(double scale){
T* newData = new T[(int)(capacity * scale)];
for (size_t i =0; i size; i++)
newData[i]= data[i];
capacity = capacity * scale;
delete[] data;
data = newData;
}
//ABS.h
#include
using namespace std;
template
class ABS {
private:
static double scale;
unsigned int size;
unsigned int capacity;
T* data;
void resize(double scale);
public:
ABS();
ABS(int capacity);
ABS(const ABS& d);
ABS& operator=(const ABS& d);
~ABS();
void push(T data);
T pop();
T peek();
unsigned int getSize();
unsigned int getMaxCapacity();
T* getData();
};
template
double ABS::scale =2.0;
template
ABS::ABS(){
capacity =1;
size =0;
data = new T[capacity];
}
template
ABS::ABS(int capacity){
this->capacity = capacity;
size =0;
data = new T[this->capacity];
}
template
ABS::ABS(const ABS& d){
capacity = d.capacity;
size = d.size;
data = new T[capacity];
for (int i =0; i size; i++)
data[i]= d.data[i];
}
template
ABS& ABS ::operator=(const ABS& d){
if (this != &d){
delete[] data;
capacity = d.capacity;
size = d.size;
data = new T[capacity];
for (size_t i =0; i size; i++)
data[i]= d.data[i];
}
return *this;
}
template
ABS::~ABS(){
delete[] data;
}
template
void ABS::push(T data){
if (size == capacity){
resize(scale);
}
this->data[size]= data;
size++;
}
template
T ABS::pop(){
if (size ==0)
throw runtime_error("Unable to pop from empty stack");
T item = data[size -1];
size--;
if (capacity >1){
if ((((double)size)/ capacity)(double)1/ scale)
resize((double)1/ scale);
}
return item;
}
template
T ABS::peek(){
if (size ==0)
throw runtime_error("Unable to peek from an empty stack");
T item = data[size -1];
return item;
}
template
unsigned int ABS::getSize(){
return size;
}
template
unsigned int ABS::getMaxCapacity(){
return capacity;
}
template
T* ABS::getData(){
return data;
}
template
void ABS::resize(double scale){
T* newData = new T[(int)(capacity * scale)];
for (size_t i =0; i size; i++)
newData[i]= data[i];
capacity = capacity * scale;
delete[] data;
data = newData;
}
 // ABQ.h #include using namespace std; template class ABQ { private:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!