Class: Zadt::MinMaxStackQueue
- Inherits:
-
Object
- Object
- Zadt::MinMaxStackQueue
- Defined in:
- lib/zadt/AbstractDataTypes/StackQueue/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
- #min ⇒ Object
- #peek ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ MinMaxStackQueue
Returns a new instance of MinMaxStackQueue.
8 9 10 11 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 8 def initialize @in = MinMaxStack.new @out = MinMaxStack.new end |
Class Method Details
Instance Method Details
#dequeue ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 29 def dequeue if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.pop end |
#empty? ⇒ Boolean
71 72 73 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 71 def empty? @in.empty? && @out.empty? end |
#enqueue(val) ⇒ Object
25 26 27 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 25 def enqueue(val) @in.push(val) end |
#help ⇒ Object
17 18 19 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 17 def help MinMaxStackQueue.help end |
#length ⇒ Object
67 68 69 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 67 def length @in.length + @out.length end |
#max ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 57 def max if @in.empty? @out.max elsif @out.empty? @in.max else [@in.max, @out.max].max end end |
#min ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 47 def min if @in.empty? @out.min elsif @out.empty? @in.min else [@in.min, @out.min].min end end |
#peek ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 38 def peek if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.peek end |
#show ⇒ Object
21 22 23 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb', line 21 def show @out.show.reverse + @in.show end |