Package Exports
- namastey-red-black-tree
- namastey-red-black-tree/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (namastey-red-black-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
namastey-red-black-tree
Brief Description
The namastey-red-black-tree package provides a JavaScript implementation of the Red-Black Tree data structure, offering efficient operations for insertion, deletion, and searching within a self-balancing binary search tree.
Features
- insert(value): Inserts a new value into the Red-Black Tree while maintaining balance.
- searchTree(value): Searches for a specific value within the tree and returns the node if found.
- inOrderTraversal(): Traverses the tree in order and prints the values in ascending order.
- rotateLeft(node): Performs a left rotation around the given node.
- rotateRight(node): Performs a right rotation around the given node.
- fixInsert(node): Ensures the tree remains balanced after an insertion.
Installation
To install the namastey-red-black-tree package globally, use the following command:
npm install -g namastey-red-black-treeExamples
const RedBlackTree = require('namastey-red-black-tree');
const rbTree = new RedBlackTree();
rbTree.insert(10);
rbTree.insert(20);
rbTree.insert(15);
console.log("In-order traversal:");
rbTree.inOrderTraversal(); // Output: 10, 15, 20
const foundNode = rbTree.searchTree(15);
console.log(foundNode ? `Found: ${foundNode.value}` : "Not Found"); // Output: Found: 15