Method: PathUtil.path_array

Defined in:
lib/util/path_util.rb

.path_array(predecessors, start, destination) ⇒ Object

Returns array of vertices on shortest path from start to destination



16
17
18
19
20
21
22
23
24
25
# File 'lib/util/path_util.rb', line 16

def self.path_array(predecessors, start, destination)
  path = []
  curr_vertex = destination
  loop do
    path.push(curr_vertex)
    return path.reverse if curr_vertex == start
    curr_vertex = predecessors[curr_vertex]
    return [] if curr_vertex.nil?
  end
end