BinarySearchTree.js
Class to create Binary Search Trees
Installation
npm install binarysearchtree-js --save
Default node structure
value: 10 // some numeric value left: null // node object or null right: null // node object or null
Usage
const BinarySearchTree = ; // traversal order type constantsBinarySearchTreeIN_ORDER;BinarySearchTreePRE_ORDER;BinarySearchTreePOST_ORDER;BinarySearchTreeLAYER_ORDER; const bst = ;bstroot; // the root nodebstcount; // the node count bst; // add a node with the value 10bst; // add multiple nodes at oncebst // Non-numeric inputs are ignored bst; // returns the node with the value 10bst; // returns false if node does not exist bst; // returns the lowest valuebst; // returns the node with the lowest valuebst; // returns the highest valuebst; // returns the node with the highest value bst; // Traverse the treebst; // and return an Arraybst; // with the node valuesbst; // in the given order // Returns a new instance of BinarySearchTree // from any tree data with any given structure // by providing the root node and its node key namesBinarySearchTree; // checks if the input tree is a valid Binary Search Tree // node.left < node.right == trueBinarySearchTree // true // also possible with different node structuresBinarySearchTree