Created
April 15, 2010 08:37
-
-
Save aeter/366845 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
# prints a depth-first-search from the starting node | |
def dfs(node): | |
visited = set() | |
visited.add(node) | |
stack = [] | |
stack.append(node) | |
while len(stack) > 0: | |
current = stack.pop() | |
print current, | |
for nodes in graph[current]: | |
if nodes not in visited: | |
stack.append(nodes) | |
visited.add(nodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment