npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lokprakash/datastructure

v2.0.4

Published

This package contains data structures like stack, binary tree...

Downloads

8

Readme

@lokprakash/datastructure

This package helps you in adding data structures like binary tree, stack and many more(in future updates). You can import this package in any JS file and start building complex data structures. Documentation will be released soon.

Recent update: Added Max heap.

Next update: Min heap.

Available data structures(As of now):

Binary tree

Stack

Queue

Linked list

Heap(Max Heap)

Official documentation will be released soon . . .

Install the package using NPM ( npm install @lokprakash/datastructures )

Import the package in your JS file

Eg,

    import * as ds from '@lokprakash/datastructure';


    //Binary tree

    let binaryTreeNode1=new ds.BinaryTree(5); //create a node with value of 5. Attributes are value, left, right.
    let binaryTreeNode2=new ds.BinaryTree(4);
    let binaryTreeNode3=new ds.BinaryTree(10);

    binaryTreeNode1.addLeft(binaryTreeNode2); //This will add a node to the left 
    binaryTreeNode1.addRight(binaryTreeNode3); //This will add a node to the right

    console.log('value of node 1', binaryTreeNode1.value);
    console.log('left node of node 1', binaryTreeNode1.left);
    console.log('right node of node 1', binaryTreeNode1.right);


    //Stack

    let stack=new ds.Stack();

    stack.pushValue(1); //this will push value 1 into the stack
    stack.pushValue(2);
    stack.pushValue(3); 


    console.log('top value of stack', stack.getTop());
    console.log('Length of the stack', stack.getLength());
    console.log('Pop the top value of the stack and return it', stack.popValue());

    //Queue

    let queue=new ds.Queue();

    queue.pushValue(1);
    queue.pushValue(2);
    queue.pushValue(3); //adds a value into the queue

    console.log(queue.popValue()); //pop the first value in the queue and returns it
    console.log(queue.getLength()); //get the current length of the queue
    console.log(queue.getTop()); //returns the first value of the queue but won't pop it out

    //Linked List

    let linkedListNode=new ds.LinkedList(1);  //this will create a node with value of 1 and the next pointer with value of null by default

    let linkedListNode2=new ds.LinkedList(2);

    linkedListNode.addNext(linkedListNode2); //this will change the "next" pointer to point to the linkedListNode2

    let node=linkedListNode;

    while(node!=null){
        
        console.log(node.value);  //prints the node value

        //increment the node pointer
        node=node.next;  
    }


    //Max heap

    let heap=new ds.Heap();


    //Insert 10 to the heap;
    heap.addElement(10); 

    //Insert 20 to the heap;
    heap.addElement(20);

    //get the root value of the heap
    let val=heap.removeElement();

    //get the size of the heap
    console.log('heap size', heap.size());