#K38967. Stack Operations Implementation
Stack Operations Implementation
Stack Operations Implementation
You are required to implement a stack data structure with a maximum capacity of 100 elements. This stack supports three operations in O(1) time:
- push x: Insert the integer x onto the stack.
- pop: Remove and output the top element of the stack. If the stack is empty, output
Empty
. - peek: Output the current top element without removing it. If the stack is empty, output
Empty
.
In the case of an operation on an empty stack, the operation must output Empty
. The commands are provided via standard input, one per line.
Note that the implementation must ensure that each operation takes constant time, i.e. O(1) time complexity.
The stack is capped at 100 elements, and no operation will cause overflow due to the constraints on the input.
inputFormat
The input consists of multiple lines. Each line contains a command in one of the following formats:
push x
where x is an integer to be pushed onto the stack.pop
which pops the top element off the stack.peek
which outputs the top element without removing it.
There can be at most 100 commands. Input is read from stdin
.
outputFormat
For every pop
or peek
command in the input, output the result on a separate line to stdout
.## sample
push 5
push 10
peek
pop
pop
pop
10
10
5
Empty
</p>