Class: Zadt::MinMaxStack
- Inherits:
-
Object
- Object
- Zadt::MinMaxStack
- Defined in:
- lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #help ⇒ Object
-
#initialize ⇒ MinMaxStack
constructor
A new instance of MinMaxStack.
- #length ⇒ Object
- #max ⇒ Object
- #min ⇒ Object
- #peek ⇒ Object
- #pop ⇒ Object
- #push(val) ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ MinMaxStack
Returns a new instance of MinMaxStack.
6 7 8 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 6 def initialize @values = [] end |
Class Method Details
.help ⇒ Object
10 11 12 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 10 def self.help Zadt::ADT:: end |
Instance Method Details
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 54 def empty? @values.empty? end |
#help ⇒ Object
14 15 16 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 14 def help MinMaxStack.help end |
#length ⇒ Object
45 46 47 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 45 def length @values.length end |
#max ⇒ Object
41 42 43 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 41 def max @values.empty? ? "Empty" : @values.last[2] end |
#min ⇒ Object
37 38 39 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 37 def min @values.empty? ? "Empty" : @values.last[1] end |
#peek ⇒ Object
33 34 35 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 33 def peek @values.last[0] end |
#pop ⇒ Object
29 30 31 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 29 def pop @values.pop[0] end |
#push(val) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 18 def push(val) if @values.empty? @values.push([val, val, val]) else cur_min = @values.last[1] cur_max = @values.last[2] @values.push([val, [val, cur_min].min, [val, cur_max].max]) @values end end |
#show ⇒ Object
49 50 51 52 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb', line 49 def show showthis = [] @values.map{|value| value[0]} end |