Tiny Binary Search Tree
BST micro library for the browser or server. When loaded as a script, Tiny Binary Search Tree is available as 'bst()'.
API
find(key)
Finds a Node in the BST
insert(key[, data])
Adds a Node to the BST
remove(key)
Removes a Node from the BST
reverse()
Returns a reverse sorted Array of the BST
show()
Returns the data
property of a Node if set, otherwise key
sort([node])
Returns a sorted Array of the BST, accepts an optional Boolean to return the Nodes instead of the key
Examples
Pointers
var bst = mybst = ; mybst;mybst;mybst;mybst; // [1, 3, 24]mybst; // [24, 3, 1]mybstleft; // 1mybst;mybstroot; // 24mybstrootleft; // 1
Data
var bst = mybst = ; mybst;mybst;mybst;mybst; // [1, 3, 24]mybst; // [24, 3, 1]mybstleft; // {abc: true}mybst;mybstroot; // {abc: false}mybstrootleft; // {abc: true}
License
Copyright (c) 2014 Jason Mulligan
Licensed under the BSD-3 license.