Question
Modify the implementation of queue data structure such that the array used to implement the queue is dynamically allocated. And deallocate the dynamically allocate queue
Modify the implementation of queue data structure such that the array used to
implement the queue is dynamically allocated.
And deallocate the dynamically allocate queue and implement the main.cpp driver file.
/* This is the header file */
#ifndef QUEUE_H_INCLUDED
#define QUEUE_H_INCLUDED
using namespace std;
const int MAX_SIZE = 7;
class emptyQueue{};
class fullQueue{};
template
class Queue{
private:
ItemType data [MAX_SIZE];
int front;
int rear;
public:
Queue();
bool isEmpty();
bool isFull();
void enQueue(ItemType);
void deQueue();
ItemType getFront();
};
#include "Queue.tpp"
#endif // QUEUE_H_INCLUDED
/* This the function definition file. */
#include "Queue.h"
#include
using namespace std;
template
Queue
this->front = -1;
this->rear = -1;
}
template
bool Queue
return (this->front == -1 && this->rear == -1);
}
template
bool Queue
return ((this->rear+1)%MAX_SIZE==this->front);
// if(this->rear==MAX_SIZE-1 && this->front==0)
// return true;
// else if(this->rear+1 == this->front)
// return true;
// else
// return false;
}
template
void Queue
if(isFull())
throw fullQueue();
else if(isEmpty()){
this->front++;
this->rear++;
data[this->rear] = item;
}
else
{
this->rear=(this->rear+1)%MAX_SIZE;
// if(this->rear == MAX_SIZE-1)
// this->rear = 0;
// else
// this->rear++;
data[this->rear] = item;
}
}
template
void Queue
if(isEmpty())
throw emptyQueue();
else if(this->front==this->rear){
this->front = -1;
this->rear = -1;
}
else{
this->front=(this->front+1)%MAX_SIZE;
// if(this->front==MAX_SIZE-1)
// this->front = 0;
// else
// this->front++;
}
}
template
ItemType Queue
if(isEmpty())
throw emptyQueue();
return data[this->front];
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer Sure lets break down the advantages and disadvantages of each operating system MSDOS Operating System Advantages Simplicity MSDOS is known for its simplicity and lightweight nature It has a sma...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