Class: Zadt::StackQueue
- Inherits:
-
Object
- Object
- Zadt::StackQueue
- Defined in:
- lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(val) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ StackQueue
constructor
A new instance of StackQueue.
- #length ⇒ Object
- #methods ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ StackQueue
Returns a new instance of StackQueue.
7 8 9 10 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 7 def initialize @in = Stack.new @out = Stack.new end |
Class Method Details
.help ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 12 def self.help puts "Here are the functions for StackQueue:" puts "#show" puts "#enqueue(value)" puts "#dequeue" puts "#length" puts "#empty?" end |
.methods ⇒ Object
21 22 23 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 21 def self.methods self.help end |
Instance Method Details
#dequeue ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 41 def dequeue if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.pop end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 54 def empty? @values.empty? end |
#enqueue(val) ⇒ Object
37 38 39 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 37 def enqueue(val) @in.push(val) end |
#help ⇒ Object
25 26 27 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 25 def help StackQueue.help end |
#length ⇒ Object
50 51 52 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 50 def length @in.length + @out.length end |
#methods ⇒ Object
29 30 31 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 29 def methods help end |
#show ⇒ Object
33 34 35 |
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 33 def show @out.show.reverse + @in.show end |