Skip to content

Instantly share code, notes, and snippets.

@diegoeche
Created February 22, 2013 16:34
Show Gist options
  • Save diegoeche/5014696 to your computer and use it in GitHub Desktop.
Save diegoeche/5014696 to your computer and use it in GitHub Desktop.
def bfs(children, element_to_find, level)
# unqued = children.shift()
unqued = children.pop()
if unqued == element_to_find
unqued
else
if unqued.is_a?(Array)
puts level
bfs(children + unqued, element_to_find, level + 1)
else
puts level
bfs(children, element_to_find, level)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment