Class: Algorithmable::Puzzles::DijkstrasTwoStacks

Inherits:
Object
  • Object
show all
Includes:
DataStructs
Defined in:
lib/algorithmable/puzzles/dijkstras_two_stacks.rb

Constant Summary collapse

MATH_OPS =
%w(sqrt cos sin tan atan2 log log2 log10)
ARITHMETICAL_OPS =
%w(+ - * /)
OPS =
ARITHMETICAL_OPS + MATH_OPS
OPEN_EXP =
'('
CLOSE_EXP =
')'

Instance Method Summary collapse

Methods included from DataStructs

#new_bag, #new_deque_queue, #new_fifo_queue, #new_lifo_queue, #new_max_priority_queue, #new_min_priority_queue, #new_ordered_symbol_table, #new_priority_queue

Methods included from DataStructs::Tree

#new_ordered_binary_tree

Methods included from DataStructs::LinkedList

#new_doubly_linked_list, #new_singly_linked_list

Constructor Details

#initialize(expression) ⇒ DijkstrasTwoStacks


12
13
14
# File 'lib/algorithmable/puzzles/dijkstras_two_stacks.rb', line 12

def initialize(expression)
  @expression = expression
end

Instance Method Details

#solveObject


16
17
18
19
20
21
# File 'lib/algorithmable/puzzles/dijkstras_two_stacks.rb', line 16

def solve
  operations = new_lifo_queue
  values = new_lifo_queue
  parse_expression(operations, values)
  values.pop
end