Class: StackQueue
- Inherits:
-
Object
- Object
- StackQueue
- Defined in:
- lib/honey_mushroom/stack_queue.rb
Instance Attribute Summary collapse
-
#stack_one ⇒ Object
Returns the value of attribute stack_one.
-
#stack_two ⇒ Object
Returns the value of attribute stack_two.
Instance Method Summary collapse
- #dequeue ⇒ Object
-
#dq ⇒ Object
shorthand = less typing =).
-
#enq(value) ⇒ Object
shorthand = less typing =).
- #enqueue(value) ⇒ Object
-
#initialize ⇒ StackQueue
constructor
A new instance of StackQueue.
Constructor Details
#initialize ⇒ StackQueue
Returns a new instance of StackQueue.
5 6 7 8 |
# File 'lib/honey_mushroom/stack_queue.rb', line 5 def initialize @stack_one = Stack.new @stack_two = Stack.new end |
Instance Attribute Details
#stack_one ⇒ Object
Returns the value of attribute stack_one.
4 5 6 |
# File 'lib/honey_mushroom/stack_queue.rb', line 4 def stack_one @stack_one end |
#stack_two ⇒ Object
Returns the value of attribute stack_two.
4 5 6 |
# File 'lib/honey_mushroom/stack_queue.rb', line 4 def stack_two @stack_two end |
Instance Method Details
#dequeue ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/honey_mushroom/stack_queue.rb', line 14 def dequeue if stack_two.stack.empty? stack_two.push(stack_one.pop) until stack_one.stack.empty? end stack_two.pop end |
#dq ⇒ Object
shorthand = less typing =)
26 27 28 |
# File 'lib/honey_mushroom/stack_queue.rb', line 26 def dq #shorthand = less typing =) dequeue end |
#enq(value) ⇒ Object
shorthand = less typing =)
22 23 24 |
# File 'lib/honey_mushroom/stack_queue.rb', line 22 def enq(value) #shorthand = less typing =) enqueue(value) end |
#enqueue(value) ⇒ Object
10 11 12 |
# File 'lib/honey_mushroom/stack_queue.rb', line 10 def enqueue(value) stack_one.push(value) end |