Skip to content

Instantly share code, notes, and snippets.

@rahulkmr
Created February 10, 2012 14:02
Show Gist options
  • Save rahulkmr/1789807 to your computer and use it in GitHub Desktop.
Save rahulkmr/1789807 to your computer and use it in GitHub Desktop.
$graph = {a: [:b, :c], b: [:d, :e], c: [:f, :g]}
def dfs_nr(node)
queue = [node]
seen = {}
while not queue.empty?
node = queue.pop
puts node
seen[node] = true
if $graph[node]
$graph[node].each {|child| queue.push child unless seen[child] }
end
end
end
dfs_nr :a
@subbu
Copy link

subbu commented Feb 10, 2012

quejue should be queue?

@rahulkmr
Copy link
Author

Yes. Rectified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment