Stack Data Structure
Design and implement the data structure "stack". Write the program to simulate the stack operations, implement all methods mentioned below. The program reads the sequence of commands and executes the corresponding operation. After processing each command the program must print one line of output. The possible commands are:
- push n - Add to the stack the number n (value n is given after the command). Print ok.
- pop - Remove the last element from the stack. Print the value of this element.
- back - Print the value of the last element, not removing it from the stack.
- size - Print the number of elements in the stack.
- clear - Clear the stack and print ok.
- exit - Print bye and terminate.
It is guaranteed that the set of input commands satisfies the following requirements: the maximum number of elements in the stack at any time does not exceed 100, all commands pop and back are correct, that is, when executed the stack contains at least one element.
Each line contains a single command.
For each command print on a separate line the corresponding result.
Input example #1
push 2 push 3 push 5 back size pop size push 7 pop clear size exit
Output example #1
ok ok ok 5 3 5 2 ok 7 ok 0 bye