An implementation of a binary search tree data structure written in JavaScript.
Includes the following methods:
insert(value)
- inserts a new node with the given value into the treeremove(value)
- removes the node holding the given value from the treefind(value)
- returns the node holding the given value in the treelevelOrder()
- traverses each node of the tree in level orderinorder()
- traverses each node of the tree inorderpreorder()
- traverses each node of the tree preorderpostorder()
- traverses each node of the tree postorderheight()
- returns the height of a node -- defined as the longest path between the node and a leaf nodedepth()
- returns the depth of a node -- defined as the distance between the node and the rootisBalanced()
- returns true/false based on whether or not the tree is balancedrebalance()
- rebalances the treeprettyPrint
- prints the tree in the console in a human reader friendly format
Also included is a small script that tests most of the tree's functionality.