Created
April 15, 2010 08:36
-
-
Save aeter/366844 to your computer and use it in GitHub Desktop.
This file contains 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
import Queue | |
# prints a breadth-first-search from the starting node | |
def bfs(node): | |
visited = set() | |
visited.add(node) | |
q = Queue.Queue() | |
q.put(node) | |
while not q.empty(): | |
current = q.get() | |
for nodes in graph[current]: | |
if nodes not in visited: | |
print nodes, | |
q.put(nodes) | |
visited.add(nodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment