Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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... 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

Practical Introduction To Data Structures And Algorithm Analysis Java Edition

Authors: Clifford A. Shaffer

1st Edition

0136609112, 978-0136609117

More Books

Students also viewed these Operating System questions

Question

Coaching and motivational behavior

Answered: 1 week ago