Clinic Waiting Room
Implement a class WaitingRoom for a clinic that sees urgent patients first. Write these methods:
WaitingRoom()starts with nobody waiting.arrive(name, urgent)adds a patient;urgentistrueorfalse. Returns how many patients are waiting now.call_next()removes the next patient and returns their name: the urgent patient who arrived earliest, or, when no urgent patient is waiting, the patient who arrived earliest. Returns""if nobody is waiting.position_of(name)returns the place ofnamein calling order (1means called next), or-1ifnameis not waiting.leave(name)removesnamewithout calling them and returnstrue, or returnsfalseifnameis not waiting.
A patient never arrives while already waiting, but may come back after being called or leaving. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
WaitingRoom()
arrive("Ann", false) returns 1
arrive("Bo", true) returns 2
arrive("Cal", false) returns 3
position_of("Ann") returns 2
call_next() returns "Bo"
call_next() returns "Ann"
leave("Cal") returns true
call_next() returns ""
Bo is urgent, so he is called before Ann even though he arrived later, and Ann stands second while he waits. Cal leaves, so the last call finds nobody.
Constraints
namehas1to5letters- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.