Implement a stack data structure. Adding to the stack should store an element until it is removed. First element added to a stack will be the last that is removed (FILO).
The stack should be a class with members:
addmethod - adds element to the stackremovemethod - removes the "top" element from the stackpeekmethod - returns "top" element (the one that should be returned) without removing (removeping) it from the stackisEmpty()- returns true if there are elements on the stack, otherwise return falsesize- numbers of items in the stack
The stack can be implemented in few different ways by using different underlying data structures. Implement each of them:
- List
- Linked list
stack = Stack.new
stack.add(1)
stack.add(2)
stack.remove # 2
stack.remove # 1
stack.remove # null