binary-search-tree-adt
BinarySearchTree ADT for browser and nodejs
Install
Download the production version or the development version.
$ npm install --save binary-search-tree-adt
$ bower install --save binary-search-tree-adt
Usage
var BinarySearchTree = ;var bst = ;
<script type="text/javascript" src="https://raw.githubusercontent.com/pasangsherpa/binary-search-tree-adt/master/dist/binary-search-tree-adt.min.js"></script><script type="text/javascript"> var bst = ; </script>
Documentation
BinarySearchTree()
Create an empty tree.
Methods
.add(element)
Add an element to tree.
element
Type: object
the element to be added to the tree.
throws "No such element" error
.remove(element) Remove an element from the tree and return the element.
element
Type: object
the element to be removed from the tree.
No such element" error
.removeAllOccurrence(element) Remove all occurrences of the element from the tree and return the element.
element
Type: object
the element to be removed from the tree.
throws "Tree is empty" error
.removeMin() Remove the minimum element in the tree and return the element.
throws "Tree is empty" error
.removeMax() Remove the maximum element in the tree and return the element.
.getRoot()
Returns the root of the tree.
Type: object
the root of the tree
throws "No such element" error
.find(element) Find an element from the tree and return the element.
element
Type: object
the specified element.
throws "Tree is empty" error
.findMin() Find the minimum element in the tree and return the element.
throws "Tree is empty" error
.findMax() Find the maximum element in the tree and return the element.
.isEmpty()
Returns true if this tree contains no elements.
Type: boolean
whether or not the tree is empty.
.size()
Returns the number of elements in the tree.
Type: int
the number of element in the tree.