Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Priority Queue as a Heap Array: Emergency Room Patient Admittance Build a priority queue as a heap stored in an array Dequeue the next priority

Priority Queue as a Heap Array: Emergency Room Patient Admittance

Build a priority queue as a heap stored in an array Dequeue the next priority item and maintaining the heap

Use the provided header file do not change in any way! Test your program with the provided driver program.

I need to implement a class of my own: a priority queue, which is a variation on the standard queue. The standard queue processes element in the first-in, first-out ("FIFO") manner typical of ordinary waiting lines. Queues can be handy, but a FIFO strategy isn't always what's needed. A hospital emergency room, for example, needs to schedule patients according to priority. A patient with a more critical problem will pre-empt others even if they have been waiting longer. This is a priority queue, where elements are prioritized relative to each other and when asked to dequeue one, it is the highest priority element in the queue that is removed. The priority queue will store a collection of structs that keep track of the patient name and an integer for the priority. Smaller integers are considered higher priority than larger ones and are dequeued ahead of larger values. The header file is provided with a struct to maintain the patient information and a class to maintain the priority queue. In this example, assume all priority numbers are unique (in a real ER program, the numbers may be from 1 to 10 plus the date/time stamp to determine who came in first when multiple have the same priority).

Header file:

#ifndef PRIORITYQUEUE_HPP #define PRIORITYQUEUE_HPP #include

//a struct to store patient information struct PatientNode { std::string name; int injurySeverity; int treatmentTime; };

class PriorityQueue { public: //perform all operations necessary to instantiate a class object //max siize of priority queue //returns none PriorityQueue(int _queueSize); //free all resources that the object has acquired ~PriorityQueue(); //enqueue new patient into priority queue //call other methods as required to maintain heap void enqueue(std::string _name, int _injurySeverity, int _treatmentTime); //remove the patient at the front of the priority queue from the queue //call other methods as required to maintain heap void dequeue(); //get name of patient at front of priority queue wile maintaining encapsulation //return name of patient at front of priority queue std::string peekName(); //get injury severity of patient at front of priority queue //return injury severity of patient at the front of priority queue int peekInjurySeverity(); //get treatment time of patient at front of priority queue //return treatment time of patient at front of priority queue int peekTreatmentTime(); //indicate if priority queue is full //return true if queue is full, false otherwise bool isFull(); //indicate if priority queue is empty //true if queue is empty, false otherwise bool isEmpty();

private: //maintain heap properties by swapping node with parent if necessary //index of node that may violate heap properties void repairUpward(int nodeIndex); //maintain heap properties by swapping node with child if necessary void repairDownward(int nodeIndex);

PatientNode* priorityQueue; int currentQueueSize; int maxQueueSize; };

#endif // PRIORITYQUEUE_HPP

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 Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions