Skip to content

Instantly share code, notes, and snippets.

@GAierken
Last active July 14, 2021 16:00
Show Gist options
  • Save GAierken/d1b33f93d2818ada2810932805b2ffa1 to your computer and use it in GitHub Desktop.
Save GAierken/d1b33f93d2818ada2810932805b2ffa1 to your computer and use it in GitHub Desktop.
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