kotlin-coding-challenges

Stack

Instructions

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:

The stack can be implemented in few different ways by using different underlying data structures. Implement each of them:

Challenge Solution

Examples

val s = new Stack()
s.add(1)
s.add(2)
s.remove() // 2
s.remove() // 1
s.remove() // null