Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a generic ADT PriorityQueue.cpp and PriorityQueue.h provided below using C++ templates and a single linear linked list A priority queue is a queue in

Implement a generic ADT PriorityQueue.cpp and PriorityQueue.h provided below using C++ templates and a single linear linked list

A priority queue is a queue in which items are stored in an order determined by a numeric priority value; where a task with priority 1 comes before a task with priority 2. This interpretation means lower numerical value has a higher priority. Thus, a priority queue is not a FIFO structure.

Implement the functions provided within the tableimage text in transcribed

Note: Queue Node is defined as a struct:

struct QueueNode{

ItemType info; int priority;

QueueNode * next;};

Here is an example of how it output would look like:

left is input and right is >>>>>>> output

image text in transcribed

PriorityQueue.cpp

#include #include #include "PriorityQueue.h"

using std::exception; using namespace std;

template struct QueueNode { ItemType info; int priority; QueueNode* next; }

template PriorityQueue::PriorityQueue() { }

template PriorityQueue::PriorityQueue(int max) {

}

template int PriorityQueue::Length() {

}

template void PriorityQueue::MakeEmpty() {

}

template bool PriorityQueue::IsFull() const { }

template bool QueType::IsEmpty() const { return (front == NULL); }

template void PriorityQueue::Dequeue(ItemType& item) { if (IsEmpty()) throw EmptyQueue(); else { } }

template void PriorityQueue::Enqueue(ItemType newItem) { if (IsFull()) throw FullQueue(); else { } }

template int PriorityQueue::Peek() { }

template ItemType PriorityQueue::PeekPriority() { }

template void PriorityQueue::PrintQueue(std::ostream &out) { }

template PriorityQueue::~PriorityQueue() { }

-------------------------------------

PriorityQueue.h

#include #include

class FullQueue {};

class EmptyQueue {};

template class PriorityQueue { public: PriorityQueue(); // Class constructor.

PriorityQueue(int max);

~PriorityQueue();

void MakeEmpty(); bool IsEmpty() const;

bool IsFull() const;

void Enqueue(ItemType newItem); void Dequeue(ItemType& item);

int Length();

int Peek();

ItemType PeekPriority() void PrintQueue(std::ostream &out);

private: int priority; ItemType* info; QueueNode* next; };

Enqueue0 Adds value at the appropriate position in the queue as determined by the numerio value priority. As in conventional English usage, lower numeric values correspond to a higher urgency, so that a task of priority 1 comes before a task with priority 2. If the Removes the value at the front of the queue and returns it to the caller. Calling ameter is it defaults to on a e throws an Peek0 Returns the value of the most urgent item in the queue without removing it from ue throws an Calling peek on an priority of the most PeekPriority 0 Returns the urgent item removing it from in the queue without throws arn MakeEmm GetLen PrintQueue0 Prints Queue items ordered from front to rear the queue. Calling peek on an emp Removes all elements from the Returns the number of elements currently in the IsEmpty 0 Returns true if the queue is empty and false otherwise IsFull 0 Returns true if the queue is full and false otherwise

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago