OlveraeUNSW
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 at head and wrapping for count slots. So traverse with items[(head + k) % CAP] for k from 0 to count-1 — do not read straight from 0 to tail, which breaks on wraparound.
Pitfall: a D on an empty queue is a no-op (do nothing).

Input

  • Line 1: number of ops m.
  • Next m lines: E v or D.

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