Last active
July 14, 2021 16:00
-
-
Save GAierken/d1b33f93d2818ada2810932805b2ffa1 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