Created
February 26, 2020 22:11
-
-
Save Giagnus64/6212f3db789073593d4f21fcafd3e9a6 to your computer and use it in GitHub Desktop.
DFS without helpers
This file contains hidden or 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
traverseDFS(type) { | |
//if there is no root, return false | |
if (!this.root) { | |
return false; | |
} | |
//make a variable for tree values | |
const treeValues = []; | |
//current values always starts at root | |
let current = this.root; | |
//helper methods go here | |
//switch statment to select proper order and start recursive function calls | |
switch (type) { | |
case "pre": | |
preOrderHelper(current); | |
break; | |
case "post": | |
postOrderHelper(current); | |
break; | |
case "in": | |
inOrderHelper(current); | |
break; | |
} | |
//return array | |
return treeValues; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment