Class: Mementus::DepthFirstSearch
- Inherits:
-
Object
- Object
- Mementus::DepthFirstSearch
- Defined in:
- lib/mementus/depth_first_search.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(graph, start_id) ⇒ DepthFirstSearch
constructor
A new instance of DepthFirstSearch.
Constructor Details
#initialize(graph, start_id) ⇒ DepthFirstSearch
Returns a new instance of DepthFirstSearch.
3 4 5 6 7 |
# File 'lib/mementus/depth_first_search.rb', line 3 def initialize(graph, start_id) @graph = graph @start_id = start_id @visited = { @start_id => true } end |
Instance Method Details
#each(&block) ⇒ Object
9 10 11 |
# File 'lib/mementus/depth_first_search.rb', line 9 def each(&block) visit(@start_id, &block) end |