Skip to content
C

Stack Using Two Queues

Mediumjavapythonccppjavascript

Implement a stack using two queues, so that operations still behave in Last In, First Out order. (Each push may take time proportional to the current size, so the number of operations is kept small.)

Input Format

The first line contains an integer Q. Each of the next Q lines is one of: push X, pop, top, empty.

Output Format

For each pop or top, print the element (or -1 if empty). For each empty, print 1 if empty, otherwise 0. One value per line.

Input (stdin)

Output

Run your code to see output here...