Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help debuggine my code so it will pass all the test cases. Please help! / / * * * * * * *

I need help debuggine my code so it will pass all the test cases. Please help! //**********************************
//Write your code below here
//**********************************
template
class QueueForCS2420 : public BaseQueue {
public:
// TODO: Complete constructor, copy constructor, copy assignment, and destructor, and all other needed methods
QueueForCS2420(const int capacity);
~QueueForCS2420();
QueueForCS2420(const QueueForCS2420& objToCopy);
const QueueForCS2420& operator=(const QueueForCS2420& objToCopy);
void push_back(const T& data);
void pop_front();
T front() const;
T back() const;
unsigned int size();
private:
// TODO: Supply the 5 needed data members
T* arr{ nullptr };
unsigned int capacity{0};
unsigned int slots{0};
unsigned int head{0};
unsigned int tail{0};
};
template
QueueForCS2420::QueueForCS2420(const int capacity){
// TODO: Complete this
this->arr = new T[capacity];
this->capacity = capacity;
return;
}
template
QueueForCS2420::~QueueForCS2420(){
// TODO: Complete this
delete[] this->arr;
}
template
QueueForCS2420::QueueForCS2420(const QueueForCS2420& objToCopy){
this->capacity = objToCopy.capacity;
this->slots = objToCopy.slots;
this->head = objToCopy.head;
this->tail = objToCopy.tail;
this->arr = new T[this->capacity];
for (unsigned int i =0; i this->capacity; ++i){
this->arr[i]= objToCopy.arr[i];
}
}
template
const QueueForCS2420& QueueForCS2420::operator=(const QueueForCS2420& objToCopy){
if (this != &objToCopy){
if (this->arr != nullptr){
delete[] this->arr;
}
this->capacity = objToCopy.capacity;
this->slots = objToCopy.slots;
this->head = objToCopy.head;
this->tail = objToCopy.tail;
this->arr = new T[this->capacity];
for (unsigned int i =0; i this->capacity; ++i){
this->arr[i]= objToCopy.arr[i];
}
}
return *this;
}
template
void QueueForCS2420::push_back(const T& data){
if (slots !=0)
{
if (slots == capacity){
std::cout "Error: Queue is full." std::endl;
return;
arr[tail]= data;
++tail;
}
if (tail == capacity){
tail =0;
}
++slots;
}
if (slots ==0)
{
++slots;
}
}
template
void QueueForCS2420::pop_front(){
if (slots ==0){
std::cout "Error: Queue is empty." std::endl;
return;
}
++head;
if (head == capacity){
head =0;
}
--slots;
}
template
T QueueForCS2420::front() const {
if (slots ==0){
throw std::out_of_range("Error: Queue is empty.");
}
return arr[head];
}
template
T QueueForCS2420::back() const {
if (slots ==0){
throw std::out_of_range("Error: Queue is empty.");
}
// If tail is at 0, the data is at index capacity -1
unsigned int tailIndex =(tail ==0)?(capacity -1) : (tail -1);
return arr[tailIndex];
}
template
unsigned int QueueForCS2420::size(){
/*if (slots ==0)
{
return slots =4;
}*/
return slots;
}
//**********************************
//Write your code above here
//**********************************
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago