Implement Queue Using Arrays
Implement a queue data structure using a circular array.
Input format
The first line contains Q. Each of the next Q lines is one of: enqueue x, dequeue, front, size.
Output format
For each dequeue print the removed value, for each front print the front value, for each size print the element count — one per line. dequeue/front on an empty queue print -1.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
10
enqueue 92
size
dequeue
dequeue
enqueue 78
dequeue
dequeue
enqueue 82
enqueue 22
sizeExpected output
1
92
-1
78
-1
2Example 2
Input
7
enqueue 43
enqueue 51
front
dequeue
dequeue
enqueue 24
sizeExpected output
43
43
51
1