Skip to content
C

Implement Stack

Easyjavapythonccppjavascript

Implement a stack that supports push, pop, peek and empty operations, processing a stream of operations.

Input Format

The first line contains an integer Q, the number of operations. Each of the next Q lines is one of: push X — push integer X pop — remove and return the top element peek — return the top element without removing it empty — return whether the stack is empty

Output Format

For each pop or peek, print the element (or -1 if the stack is empty). For each empty, print 1 if the stack is empty, otherwise 0. Print one value per line.

Input (stdin)

Output

Run your code to see output here...