MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / searchDFS

Function searchDFS

Trees/DepthFirstSearch.js:27–45  ·  view source on GitHub ↗
(tree, value)

Source from the content-addressed store, hash-verified

25}
26
27function 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
47export { searchDFS, traverseDFS }

Callers 2

traverseDFSFunction · 0.85

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected