Last active
September 9, 2017 15:32
-
-
Save scriptonian/d11401891c2af86e729b27fd7f4c26c8 to your computer and use it in GitHub Desktop.
Binary Search Tree Traversal
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
BinarySearchTree.prototype = { | |
/* | |
other code here | |
*/ | |
inOrder: function(node){ | |
if (node !== null) { | |
//print the left subtree recursively | |
this.inOrder(node.left); | |
//print the root node | |
console.log(node.toString()); | |
//print the right subtree recursively | |
this.inOrder(node.right); | |
} | |
}, | |
preOrder: function(node){ | |
if (node !== null) { | |
//print the root node | |
console.log(node.toString()); | |
//print the left subtree recursively | |
this.preOrder(node.left); | |
//print the right subtree recursively | |
this.preOrder(node.right); | |
} | |
}, | |
postOrder: function(node){ | |
if (node !== null) { | |
//print the left subtree recursively | |
this.postOrder(node.left); | |
//print the right subtree recursively | |
this.postOrder(node.right); | |
//print the root node | |
console.log(node.toString()); | |
} | |
} | |
/* | |
other code htere | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment