A simple AVL tree implementation.
$ npm install --save simpleavltree
var AVLTree = require('simpleavltree');
/**
* Build the AVL tree
*/
var tree = new AVLTree(44);
tree.insert(17)
.insert(78)
.insert(32)
.insert(88)
.insert(50)
.insert(48)
.insert(62)
.insert(54);
/**
* Delete a node from the tree
*/
tree.search(54).deleteNode();
/**
* Populate an array from traversing (in order) the tree
*/
var arr = tree.traverse();
arr.forEach(function (val) {
console.log(val.value);
});
Takes an int as input and inserts the new node into the tree
var AVLTree = require('simpleavltree');
/**
* Build the AVL tree
*/
var tree = new AVLTree(44);
tree.insert(17)
.insert(78);
Takes an int as input and returns the node that was searched for.
var AVLTree = require('simpleavltree');
/**
* Build the AVL tree
*/
var tree = new AVLTree(44);
tree.insert(17)
.insert(78);
var searchedNode = tree.search(54)
Takes a node as input and deletes it from the tree.
var AVLTree = require('simpleavltree');
/**
* Build the AVL tree
*/
var tree = new AVLTree(44);
tree.insert(17)
.insert(78);
/**
* Delete a node from the tree
*/
tree.search(54).deleteNode();
Takes a configuration object specifying the traversal order.
{
inOrder:false,
preOrder:false,
postOrder:true
}
var AVLTree = require('simpleavltree');
/**
* Build the AVL tree
*/
var tree = new AVLTree(44);
tree.insert(17)
.insert(78);
var arr = tree.traverse({inOrder:false,preOrder:false,postOrder:true});
arr.forEach(function (val) {
console.log(val.value);
});