Question: 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 tableImplement a generic ADT PriorityQueue.cpp and PriorityQueue.h provided below using C++ templates

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

and a single linear linked list A priority queue is a queue

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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!