Class: Zadt::MinMaxStackQueue
- Inherits:
-
Object
- Object
- Zadt::MinMaxStackQueue
- Defined in:
- lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(val) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ MinMaxStackQueue
constructor
A new instance of MinMaxStackQueue.
- #length ⇒ Object
- #max ⇒ Object
- #methods ⇒ Object
- #min ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ MinMaxStackQueue
Returns a new instance of MinMaxStackQueue.
8 9 10 11 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 8 def initialize @in = MinMaxStack.new @out = MinMaxStack.new end |
Class Method Details
.help ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 13 def self.help puts "Here are the functions for MinMaxStackQueue:" puts "#show" puts "#enqueue(value)" puts "#dequeue" puts "#min" puts "#max" puts "#length" puts "#empty?" end |
.methods ⇒ Object
24 25 26 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 24 def self.methods self.help end |
Instance Method Details
#dequeue ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 44 def dequeue if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.pop end |
#empty? ⇒ Boolean
77 78 79 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 77 def empty? @in.empty? && @out.empty? end |
#enqueue(val) ⇒ Object
40 41 42 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 40 def enqueue(val) @in.push(val) end |
#help ⇒ Object
28 29 30 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 28 def help MinMaxStackQueue.help end |
#length ⇒ Object
73 74 75 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 73 def length @in.length + @out.length end |
#max ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 63 def max if @in.empty? @out.max elsif @out.empty? @in.max else [@in.max, @out.max].max end end |
#methods ⇒ Object
32 33 34 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 32 def methods help end |
#min ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 53 def min if @in.empty? @out.min elsif @out.empty? @in.min else [@in.min, @out.min].min end end |
#show ⇒ Object
36 37 38 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb', line 36 def show @out.show.reverse + @in.show end |