Skip to content

Instantly share code, notes, and snippets.

@Giagnus64
Created February 26, 2020 22:11
Show Gist options
  • Save Giagnus64/6212f3db789073593d4f21fcafd3e9a6 to your computer and use it in GitHub Desktop.
Save Giagnus64/6212f3db789073593d4f21fcafd3e9a6 to your computer and use it in GitHub Desktop.
DFS without helpers
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