Newts Parading Majestically
Wondering what’s next for npm?Check out our public roadmap! »

print-bstTypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

print-bst

Binary Search Tree Implementation with Print Tree Functionality

Usage

 
const BinarySearchTree = require('print-bst');
 
let bst = new BinarySearchTree();
bst.insert(30); // insert one element
bst.insert(21);
bst.insert(42);
console.log(bst.print()); // will print tree
 
//   _30   
//  /   \  
// 21    42
 
bst.bulkInsert([30,21,42,14,25,34,12,54,32,28]); // insert array of elements at a time
console.log(bst.print()); // will print tree
 
//         _______30______      
//        /               \     
//      _21               _42   
//     /   \             /   \  
//   _14    25         _34    54
//  /         \       /         
// 12          28    32         
 
bst.remove(42); // remove element
bst.remove(21); // remove element
console.log(bst.print()); // will print tree
 
//         ____30______   
//        /            \  
//      _25            _54
//     /   \          /   
//   _14    28      _34   
//  /              /      
// 12             32     
 
bst.search(28); // returns true
bst.search(18); // returns false
 

Install

npm i print-bst

DownloadsWeekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

5.55 kB

Total Files

6

Last publish

Collaborators

  • avatar