avl-trees-js

1.2.3 • Public • Published

avl-trees-js is a light package that allows you to perform all the avl tree operations efficiently

Installation

$ npm install avl-trees-js 

Importing

// Using Node.js `require()`
const avl= require('avl-trees-js ');
 
// Using ES6 imports
import avl from 'avl-trees-js ';

Insertion

avl.insert(value);

Traversing

you can traverse in: inOrder,postOrder and PreOrder

avl.traverse('orderToTraverse',cb());

e.g

avl.traverse('postOrder',cb());

by default you traverse in order i.e

avl.traverse(cb());

Getting Maximum and Minimum

avl.Max() 

returns the node with the maximum value. To get the value just add getData() to the retrieved node. note: .getData() retrieves the stored value in a node i.e

avl.Max().getData()

same applies to min except we use Min() in place of Max()

deleting nodes from the tree

avl.remove(nodeValue)

removes the node with the value and rebalances the tree

finding the node with the a given value

avl.find(nodeValue)

returns null incase no node with that value exists

Testing

npm test

/avl-trees-js/

    Package Sidebar

    Install

    npm i avl-trees-js

    Weekly Downloads

    1

    Version

    1.2.3

    License

    MIT

    Unpacked Size

    18.5 kB

    Total Files

    4

    Last publish

    Collaborators

    • samuelmayna