Class: Zadt::StackQueue
- Inherits:
-
Object
- Object
- Zadt::StackQueue
- Defined in:
- lib/zadt/AbstractDataTypes/StackQueue/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
- #peek ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ StackQueue
Returns a new instance of StackQueue.
7 8 9 10 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 7 def initialize @in = Stack.new @out = Stack.new end |
Class Method Details
.help ⇒ Object
12 13 14 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 12 def self.help Zadt::ADT:: end |
Instance Method Details
#dequeue ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 28 def dequeue if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.pop end |
#empty? ⇒ Boolean
50 51 52 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 50 def empty? @in.empty? && @out.empty? end |
#enqueue(val) ⇒ Object
24 25 26 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 24 def enqueue(val) @in.push(val) end |
#help ⇒ Object
16 17 18 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 16 def help StackQueue.help end |
#length ⇒ Object
46 47 48 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 46 def length @in.length + @out.length end |
#peek ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 37 def peek if @out.empty? @in.length.times do @out.push(@in.pop) end end @out.peek end |
#show ⇒ Object
20 21 22 |
# File 'lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb', line 20 def show @out.show.reverse + @in.show end |