This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `node-binary-search-tree`

with all `npm`

packages installed. **Try it out**:

var nodeBinarySearchTree = require("node-binary-search-tree")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

NodeJS module to implement a binary search tree

```
npm install node-binary-search-tree --save
```

Create a new tree

```
var BinaryTree = require('node-binary-search-tree');
var tree = new BinaryTree();
```

Determine if the tree contains a value
*Returns a boolean value*

```
tree.contains(9);
```

Add a single value to a tree

```
tree.add(1);
tree.add(23);
tree.add(17);
```

Add an array of values to a tree

```
tree.addArray([1, 14, 25, 6, 19]);
```

Remove a value from a tree

```
tree.remove(16);
```

Get the size of the tree

```
tree.size();
```

Get the minimum value in the tree

```
tree.min();
```

Get the maximum value in the tree

```
tree.max();
```

Get a sorted array of the tree's values

```
tree.toArray();
```

Merge one tree into another

```
tree1.merge(tree2);
```

Balance the tree

```
tree.balance();
```

```
npm test
```

```
./release.sh
```

Luke Epp lucasfepp@gmail.com

- package on npmhttps://npmjs.com/package/node-binary-search-tree
- homepagehttps://github.com/lfepp/binary-search-tree
- licenseUNLICENSED

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free