Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab will simulate a hospital waiting room with a patients name and priority number. This will be possible by using a priority queue in

This lab will simulate a hospital waiting room with a patients name and priority number. This will be possible by using a priority queue in C++ that stores the name of a patient and a non-negative integer priority. The queue will allow us to insert a patients name, to remove the name of the patient with the lowest priority, and to decrease a patients priority.

The public member functions, described below, are required:

priorityqueue() - The default constructor creates an empty priority queue.

void push(int key, int priority) - This function inserts a new element with a given key and priority. The key must not appear in the queue and the priority must not be negative. You can use assert statements to check these and other explicitly stated preconditions.

void pop() - This function removes the element with smallest priority. No value is returned. It is an error to pop from an empty priority queue.

int topPriority() const - Returns the element of least priority.

int topKey() const - This top function gives the key of the element of least priority.

void reducePriority(int key, int newpriority) - This function lowers the priority of a specified element. It is an error if the key is not present in the priority queue, if the new priority is negative, or if it is greater than the current priority.

int getPriority(int key) - This function returns the priority of the element with the specified key. It returns 1 if the key is not present in the priority queue.

bool isEmpty() const - This function tells us if the priority queue is empty.

bool isPresent(int key) const - This function returns true if there is an element in the queue with the specified key.

void clear() - This function empties the priority queue.

int size() const - This is a function that returns the number of elements in the queue.

Write the functions above in a specification file, priorityqueue.h . Then, apply the functions in the implementation file, priorityqueue.cpp. Lastly, write a main function to demonstrate that the functions work correctly.

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions