-
-
Save russellf9/d0e6d474fb795c1b82ed6351210e7a4e to your computer and use it in GitHub Desktop.
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
inOrderDFS(){ | |
// a variable to store the visited nodes | |
let result = [] | |
// helper function -- accepts a node | |
function traverse(node){ | |
// if node has left, recursion to find the leftest leaf node | |
if(node.left) traverse(node.left) | |
// push the node to the result | |
result.push(node) | |
// if node has right, recurstion to find the rightest leaf node | |
if(node.right) traverse(node.right) | |
} | |
// invoke the helper function with the root | |
traverse(root) | |
// return the final result | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment