Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bfs(tree, value) {
- var queue = []
- queue.push(tree[0])
- while (queue.length !== 0) {
- for (let i = 0; i < queue.length; i++) {
- var node = queue.shift()
- if (node.value === value) {
- return node
- }
- if (node.left) {
- queue.push(tree[node.left])
- }
- if (node.right) {
- queue.push(tree[node.right])
- }
- }
- }
- console.log('Unable to find node')
- }
Add Comment
Please, Sign In to add comment