Created
April 13, 2015 19:27
-
-
Save jacksonhoose/6654ea8f8570a3ae3ba9 to your computer and use it in GitHub Desktop.
BFS
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
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