Queue: process a sequence of enqueue/dequeue ops
Read m operations, each E v (enqueue v) or D (dequeue). Process them with a queue and print the value dequeued for each D; if the queue is empty on a D, print -1. All outputs on one line, space-separated.
Complete enqueue and dequeue (first-in-first-out).
Pitfalls (straight from the bug lab): (1) check the queue is non-empty (
count > 0) beforedequeue; if empty return-1— do not read garbage or letcountgo negative. (2)headadvances on dequeue, preserving FIFO.
Input
- Line 1: number of ops
m. - Next
mlines:E v(enqueue integer v) orD(dequeue).
Output
- One line: the value for each
D(or-1if empty), space-separated, a space after each. If there are noDops, print just a newline.
Example: input 6 / E 1 / E 2 / D / E 3 / D / D -> 1 2 3 (FIFO: out come 1, 2, 3).