Implement Queue using Stacks

EasyStack & Queue
Next
StackQueueDesign

Build a first-in-first-out queue using only two stacks. You are given a list of operations to run on it: push x adds x to the back, pop removes and reports the front, peek reports the front without removing it, and empty reports whether the queue has no elements.

Input

Line 1: q, the number of operations. Next q lines: one operation each (push x, pop, peek or empty).

Output

For each pop and peek print the value, and for each empty print true or false. One result per line, in order. Operations are always valid (never pop or peek an empty queue).

Constraints

1 <= q <= 10^4 1 <= x <= 99

Example 1
Input
5
push 1
push 2
peek
pop
empty
Output
1
1
false

peek shows 1, pop removes 1, and the queue still holds 2 so empty is false.

Hints

Implement Queue using Stacks - Easy Stack & Queue Problem | Skill Shiksha