Back to problems
COMP2521
Queue: Final Contents
Queue: what remains after the operations
Read m operations (E v enqueue / D dequeue). After processing, print the elements still in the queue from front to back. enqueue / dequeue are provided; complete printQueue.
Key: the queue is circular, with elements starting atheadand wrapping forcountslots. So traverse withitems[(head + k) % CAP]forkfrom 0 tocount-1— do not read straight from 0 to tail, which breaks on wraparound.
Pitfall: aDon an empty queue is a no-op (do nothing).
Input
- Line 1: number of ops
m. - Next
mlines:E vorD.
Output
- One line: the queue from front to back, a space after each element; just a newline if empty.
Example: input 5 / E 1 / E 2 / E 3 / D / E 4 -> 2 3 4 (1 was dequeued, leaving 2, 3, 4).
Samples
stdin
5 E 1 E 2 E 3 D E 4
expected
2 3 4
stdin
6 E 1 E 2 E 3 D D D
expected
c-dcc
14