Question
Problem Statement: You will write a program that manages a waiting line of patients to be processed at a hospital. First come first served is
Problem Statement: You will write a program that manages a waiting line of patients to be processed at a hospital. First come first served is not the best order to assist patients in a hospital, because some patients have more urgent and critical injuries than others. As each new patient checks in at the hospital, the staff assesses their injuries and gives that patient an integer priority rating, with smaller integers representing greater urgency. (For example, a patient of priority 1 is more urgent and should receive care before a patient of priority 2.)
Once a doctor is ready to see a patient, the patient with the most urgent (smallest) priority is seen first. That is, regardless of the order in which you add/enqueue the elements, when you remove/dequeue them, the one with the lowest priority number comes out first, then the second-smallest, and so on, with the largest priority item coming out last. Priority ties are broken by first dequeuing the same-priority patients in the order they were enqueued. A queue that processes its elements in order of increasing priority like this is also called a priority queue.
A priority queue stores a set of keys (priorities) and their associated values. This assignment models a hospital waiting room as a priority queue. If two patients in the queue have the same priority, you will break ties by choosing the patient who arrived earliest with that priority. This means that if a patient arrives at priority K and there are already other patients in the queue with priority K, your new patient should be placed after them.
Your class must support all of the following operations. constructor() In this parameterless constructor you should initialize a new empty queue. destructor In this destructor you must free up any memory used. enqueue In this function you should add the given person into your patient queue with the given priority. Duplicate names and priorities are allowed. dequeue In this function you should remove the patient with the most urgent priority from your queue, and you should also return their name as a string. Front name In this function you should return the name of the most urgent patient (the person in the front of your patient queue), without removing it or altering the state of the queue. Front priority In this function you should return the integer priority of the most urgent patient (the person in the front of your patient queue), without removing it or altering the state of the queue. Upgrade patient In this function you will modify the priority of a given existing patient in the queue. The intent is to change the patient's priority to be more urgent (a smaller integer) than its current value, perhaps because the patient's condition has gotten worse. If the given patient is present in the queue and already has a more urgent priority than the given new priority, or if the given patient is not already in the queue, your function should handle that. If the given patient name occurs multiple times in the queue, you should alter the priority of the highest priority person with that name that was placed into the queue. Is empty In this function you should return true if your patient queue does not contain any elements and false if it does contain at least one patient. clear In this function you should remove all elements from the patient queue, freeing memory for all nodes that are removed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started