CJCoding With Joseph
15free / daySign inCreate account

Emergency Room Triage

Build a class Triage that decides which emergency-room patient is seen next, using a priority_queue with 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, returns No patients and 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 calls next() four times, printing each result on its own line (see Expected Output).

The second test adds Dan (severity 1) and Eve (severity 4) and prints waiting(), 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
Topics:
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.