Class: StackQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/honey_mushroom/stack_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStackQueue

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_oneObject

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_twoObject

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

#dequeueObject



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

#dqObject

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