(tree, value)
| 25 | } |
| 26 | |
| 27 | function searchDFS(tree, value) { |
| 28 | const stack = [] |
| 29 | stack.push(tree[0]) |
| 30 | while (stack.length !== 0) { |
| 31 | for (let i = 0; i < stack.length; i++) { |
| 32 | const node = stack.pop() |
| 33 | if (node.value === value) { |
| 34 | return node |
| 35 | } |
| 36 | if (node.right) { |
| 37 | stack.push(tree[node.right]) |
| 38 | } |
| 39 | if (node.left) { |
| 40 | stack.push(tree[node.left]) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | return null |
| 45 | } |
| 46 | |
| 47 | export { searchDFS, traverseDFS } |
no test coverage detected