Skip to content

Instantly share code, notes, and snippets.

@vaidehijoshi
Created May 29, 2017 05:28
Show Gist options
  • Save vaidehijoshi/df7b4fbe8bb5fff19b977d3050fe61b9 to your computer and use it in GitHub Desktop.
Save vaidehijoshi/df7b4fbe8bb5fff19b977d3050fe61b9 to your computer and use it in GitHub Desktop.
function preorderSearch(node) {
// Check that a node exists.
if (node === null) {
return;
}
// Print the data of the node.
console.log(node.data);
// Pass in a reference to the left child node to preorderSearch.
// Then, pass reference to the right child node to preorderSearch.
preorderSearch(node.left);
preorderSearch(node.right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment