binary search tree & avl tree (self balancing tree) implementation in javascript
Package Exports
@datastructures-js/binary-search-tree
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@datastructures-js/binary-search-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@datastructures-js/binary-search-tree
Binary Search Tree & AVL Tree (Self Balancing Tree) implementation in javascript.
// BinarySearchTree<T extends number|string, U = undefined>const bst =newBinarySearchTree<number, string>();
// AvlTree<T extends number|string, U = undefined>const bst =newAvlTree<number,{id: string,count: number }>();
.insert(key[, value])
inserts a node with key/value into the tree and returns the inserted node. Inserting an node with existing key, will update the existing node's value with the new one.
const max = bst.max();
console.log(max.getKey());// 90
console.log(max.getValue());// v4
.lowerBound(k[, includeEqual]) (.floor)
finds the node with the biggest key less or equal a given value k. You can eliminate equal keys by passing second param as false. .floor is a delegate to the same function.
finds the node with the smallest key bigger or equal a given value k. You can eliminate equal keys by passing second param as false. .ceil is a delegate to the same function.