Last active
December 11, 2015 09:39
-
-
Save ianbishop/4581542 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # BFS | |
| def bfs(source, target) | |
| q = [] | |
| visited = {} | |
| q << source | |
| while !q.empty? | |
| current = q.shift | |
| visited[current] = true | |
| return if (current == target) # done | |
| current.neighbors.each do |neighbor| | |
| q << neighbor if !visited[neighbor] | |
| end | |
| end | |
| # no solution | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment