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::Queue(){

this->front = -1;

this->rear = -1;

}

template

bool Queue::isEmpty(){

return (this->front == -1 && this->rear == -1);

}

template

bool Queue::isFull(){

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::enQueue(ItemType item){

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::deQueue(){

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::getFront(){

if(isEmpty())

throw emptyQueue();

return data[this->front];

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

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... View full answer

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 Operating System Questions!