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

@geekyorion/dsa

v1.0.4

Published

A Data Structure library

Downloads

12

Readme

@geekyorion/DSAlib

npm (scoped) npm bundle size (scoped) GitHub issues GitHub license

A data structure library which implements linkedlist, tree, etc

DSA Status

  • [x] LinkedList
    • [x] Singly LinkedList
    • [ ] Dobuly LinkedList
  • [ ] Tree
  • [ ] Stack
  • [ ] Graph

basic usage

installation

To install the library please use the following command

npm i --save @geekyorion/dsa

creating instances

const LinkedList = require('@geekyorion/dsa').LinkedList;

// use the LinkedList to create a new list
const list = new LinkedList();

OR

const DSA = require('@geekyorion/dsa');
// here DSA is an object which has implemeneted Data structure within

// to create a new LinkedList
const list = new DSA.LinkedList();

1. LinkedList

Class Prototype

// properties
list.head: null | LinkedListNode
list.tail: null | LinkedListNode
list.lengthOfList: number

// method list
list.getHead(): LinkedListNode;
list.getTail(): LinkedListNode;
list.getLength(): number;
list.JSON(): JSON;
list.push(value: any): number;
list.unshift(value: any): number;
list.pop(): LinkedListNode.value;
list.shift(): LinkedListNode.value;
list.traverse(shouldReturnArray?: boolean): Array<LinkedListNode.value> | undefined;
list.insert(position: number, value: any): number;
list.remove(position: number): LinkedListNode.value;
list.removeByValue(value: LinkedListNode.value, multiRemove?: boolean): number;
list.reverse(): list;
list.getReversedValue(): Array<LinkedListNode.value>;
list.sort(shouldReturn?: boolean): list | true;
list.isEqual(anotherLinkedList: LinkedList): boolean;
list.merge(anotherLinkedList: LinkedList): number;
list.node(value: any): LinkedListNode;

Properties

const list = new LinkedList();

// get head pointer of the list
list.getHead();
// or
list.head;

// get tail pointer of the list
list.getTail();
// or
list.tail;

// get the number of nodes in the list
list.getLength();
// or
list.lengthOfList;

// All these properties can be used to generate the JSON for the list
// so to get the JSON for the list (with above properties)
list.JSON();
/*
example list: [1, 2, 3]
output:
{
    head: {
        value : 1, next: {
            value: 2, next: { value: 3, next: null }
        }
    },
    tail: {
        value: 3,
        next: null
    },
    lengthOfList: 3
}
*/

Available methods

  • push(value): adds a new value in the list at the last position (after the tail)

    list.push(1);       // return value: 1
    list.push('a');     // return value: 2
    // returns the new size of the list
    // list: [1, 'a']
  • unshift(value): adds a new value in the list at starting position (before the head)

    list.unshift(1);       // return value: 1
    list.unshift('a');     // return value: 2
    // returns the new size of the list
    // list: ['a', 1];
  • pop(): removes the last value (from the tail)

    // list: [1, 2, 3, 4]
    const value = list.pop();
    // value: 4; returns the popped value
    // list: [1, 2, 3];
  • shift(): removes the starting value (from the head)

    // list: [1, 2, 3, 4]
    const value = list.shift();
    // value: 1; returns the popped value
    // list: [2, 3, 4];
  • traverse(shouldReturnArray?): traverse the linkedlist

    • shouldReturnArray: optional; default is true
      • true: returns the array of the list values
      • false: console the list items
    // list: [1, 2, 3, 4]
    const arrayItems = list.traverse();
    // arrayItems: [1, 2, 3, 4]; 
      
    list.traverse(false);
    // console output:
    /*
    1
    2
    3
    4
    */
  • insert(position, value): insert a value at particular position (zero based index)

    // list: [1, 2, 4, 5]
    list.insert(2, 3);     // return value: 5
    // returns the new size of the list
    // list: [1, 2, 3, 4, 5];
  • remove(position): remove a value from particular position (zero based index)

    // list: [1, 2, 3, 4, 5]
    const removedValue = list.remove(2);
    // removedValue: 3; returns the removed value
    // list: [1, 2, 4, 5];
  • removeByValue(value, multiRemove?): removes the given value from list

    • multiRemove: optioanl; default is false
      • true: remove all the matches
      • false: remove only the first match
    // list: [1, 2, 2, 2, 5]
    list.remove(2);         // returns 4; returns the new length of the list
    // output: [1, 2, 2, 5]
    list.remove(2, true);   // returns 2
    // output: [1, 5]
  • reverse(): reverse the list (modifies the original list)

    // list: [1, 2, 3, 4, 5]
    list.reverse();     // returns the pointer to the current list
    // output: [5, 4, 3, 2, 1]
  • getReversedValue(): returns the array of list value in reversed order (doesn't modify the original list)

    // list: [1, 2, 3, 4, 5]
    const reverseValueArray = list.getReversedValue();     // returns the array
    // reverseValueArray: [5, 4, 3, 2, 1]
    // but the list is still the same
  • sort(shouldReturn?): sort the list

    • shouldReturn: optional; default is false
      • true: returns the pointer to the current list (sorted)
      • false: return 'true' in case of successful sort
    // list: [3, 5, 1, 2, 4]
    list.sort();     // returns true
    // output: [1, 2, 3, 4, 5]
  • isEqual(anotherLinkedList): checks whether list is equal with provided list or not

    • anotherLinkedList: an another instance of the LinkedList class
    // list: [1, 2, 3]
    // anotherList: [1, 2, 3]
    let isEqual = list.isEqual(anotherList);
    // isEqual: true
    list.push(4);
    isEqual = list.isEqual(anotherList);
    // isEqual: false
  • merge(anotherLinkedList): merge the another linkedlist

    • anotherLinkedList: an another instance of the LinkedList class
    // list: [1, 2, 3]
    // anotherList: [4, 5]
    list.merge(anotherList);        // returns 5; returns the new length of the list
    // list: [1, 2, 3, 4, 5]
  • node(value): returns the node with the provided value which can be used to create the new list path from any node

    // list: [1, 2, 4]
    const node = list.node(3);
    list.insert(2, node);
    console.log(list.JSON());
    /*
    {
        head: {
            value: 1, next: {
                value: 2, next: {
                    value: { value: 3, next: null },
                    next: { value: 4, next: null }
                }
            }
        },
        tail: { value: 4, next: null },
        lengthOfList: 4
    }
    */