Created
October 6, 2021 05:50
-
-
Save misterpoloy/35cc6fa02ff57717a85ed9f23aaffdbe to your computer and use it in GitHub Desktop.
breadthFirstSearch AlgoExpert Implementation
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 breadthFirstSearch(array) { | |
const queue = [this] | |
while (queue.length) { | |
const current = queue.shift() | |
array.push(current.name) | |
for (const child of current.children) { | |
queue.push(child) | |
} | |
} | |
return array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See BST Breadth First Traversal