Hi, I have implementation graph as a dictionary.
I done finding a path between two nodes, but I don't know how find all
paths between two nodes. Anybody help or give me an advice?
My code:

class Graph
  attr_accessor :graph

  def initialize
    @graph = Hash.new { |hash, key| hash[key] = [] }
  end

  def addEdge(a, b)
    @graph[a] << b
    @graph[b] << a
  end


  def searchPath(a, b, result)
    result << a
    if a == b
      return result
    end
    @graph[a].each do |v|
      if ! result.include?(v)
        return searchPath(v, b, result)
      end
    end
  end

end

g2 = Graph.new
puts g2.graph
g2.addEdge('a','e')
g2.addEdge('e','f')
g2.addEdge('f','b')
g2.addEdge('e','b')
g2.addEdge('a','c')
g2.addEdge('c','b')
puts g2.graph
p g2.searchPath('a','b', [])

-- 
Posted via http://www.ruby-forum.com/.