Class: Algorithmable::Cups::StacksAndQueues::StackWithMin
- Inherits:
-
DataStructs::Stack
- Object
- DataStructs::Stack
- Algorithmable::Cups::StacksAndQueues::StackWithMin
- Defined in:
- lib/algorithmable/cups/stacks_and_queues/stack_with_min.rb
Constant Summary collapse
- MAX_INT =
2**32
Constants included from Errors
Instance Method Summary collapse
Methods inherited from DataStructs::Stack
#initialize, #peek, #pop, #to_s
Constructor Details
This class inherits a constructor from Algorithmable::DataStructs::Stack
Instance Method Details
#min ⇒ Object
16 17 18 19 |
# File 'lib/algorithmable/cups/stacks_and_queues/stack_with_min.rb', line 16 def min return MAX_INT if empty? peek.min end |
#push(item) ⇒ Object
10 11 12 13 14 |
# File 'lib/algorithmable/cups/stacks_and_queues/stack_with_min.rb', line 10 def push(item) new_min = [item, min].min node = NodeWithMin.new item, new_min super node end |