Two stale entries
transcript
Two requests are cancelled. Both sit on top of the heap. The code pops once. It serves a cancelled request.
Requests one and two are cancelled. An if pops only request one. Request two is stale, but served. A loop pops both. Request three is served.
Check the top of the heap. Pop while it is stale, again and again. Then serve the top. If the heap is empty, answer minus one.
Test a cancel for a request that never arrived. Test a cancel after serving. Test an empty heap after the cleanup. Each one needs its own test.
Two cancels can follow each other. Both cancelled entries may be on top. So stale entries stack up there. One check cannot clear them, but a loop can. Test this case by hand before you submit.
Several stale entries can stack up. So always use a loop. Full breakdown in the lecture.