← Back to STL Containers
Question 499
Emergency Room Triage
Emergency Room Triage
Build a classTriagethat decides which emergency-room patient is seen next, using apriority_queuewith a custom comparator. Patients with a higher severity number go first; among patients with equal severity, the one who arrived earlier goes first. Methods: -void addPatient(const string& name, int severity): registers a patient. -string next(): removes and returns the name of the patient to see next (highest severity; earliest arrival on ties). If nobody is waiting, returnsNo patientsand changes nothing. -int waiting() const: returns how many patients are still waiting. The first test adds Ann (severity 3), Bob (severity 3), Cara (severity 5), then callsnext()four times, printing each result on its own line (see Expected Output). The second test adds Dan (severity 1) and Eve (severity 4) and printswaiting(),next(),waiting(),next(),waiting(): 2 Eve 1 Dan 0 Do NOT write a main function.
Expected Output:
Cara Ann Bob No patients 2 Eve 1 Dan 0
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL ContainersQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.