Skip to content

Instantly share code, notes, and snippets.

@jacksonhoose
Created April 13, 2015 19:27
Show Gist options
  • Save jacksonhoose/6654ea8f8570a3ae3ba9 to your computer and use it in GitHub Desktop.
Save jacksonhoose/6654ea8f8570a3ae3ba9 to your computer and use it in GitHub Desktop.
BFS
function BFS(root, callback){
var queue = [];
queue.push(root);
while(queue.length){
var current = queue.shift();
callback(current.value);
for(var i = 0; i < current.children.length; i++){
queue.push(current.children[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment