1.2.1 • Published 10 years ago

tiny-bst v1.2.1

Weekly downloads
5
License
-
Repository
github
Last release
10 years ago

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()'.

build status

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   = require("tiny-bst"),
    mybst = bst();

mybst.insert(3);
mybst.insert(24);
mybst.insert(1);
mybst.sort();    // [1, 3, 24]
mybst.reverse(); // [24, 3, 1]
mybst.find(3).left.show(); // 1
mybst.remove(3);
mybst.root.show(); // 24
mybst.root.left.show(); // 1

Data

var bst   = require("tiny-bst"),
    mybst = bst();

mybst.insert(3, {abc: true});
mybst.insert(24, {abc: false});
mybst.insert(1, {abc: true});
mybst.sort();    // [1, 3, 24]
mybst.reverse(); // [24, 3, 1]
mybst.find(3).left.show(); // {abc: true}
mybst.remove(3);
mybst.root.show(); // {abc: false}
mybst.root.left.show();  // {abc: true}

License

Copyright (c) 2014 Jason Mulligan
Licensed under the BSD-3 license.

1.2.1

10 years ago

1.2.0

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.1.0

11 years ago