Implementation of the Stack class.