Skip to content

Instantly share code, notes, and snippets.

@jepser
Created April 5, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jepser/a25fa0d52dee4cb5857ca0a9abe61a16 to your computer and use it in GitHub Desktop.
Save jepser/a25fa0d52dee4cb5857ca0a9abe61a16 to your computer and use it in GitHub Desktop.
Tree - DFS preorder
getValues() {
let result = [];
function traverse(node) {
result.push(node.value);
if (node.left) {
traverse(node.left);
}
if (node.right) {
traverse(node.right);
}
}
traverse(this);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment