Created
July 2, 2019 14:43
-
-
Save verdi327/fbcd098921ea2464e500d1266e3e6e1a to your computer and use it in GitHub Desktop.
dfs-preorder.js
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
preOrder(result=[]) { | |
if (!this.left && !this.right) { | |
return result.push(this.key); | |
} | |
result.push(this.key); | |
if (this.left) { | |
this.left.preOrder(result); | |
} | |
if (this.right) { | |
this.right.preOrder(result); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment