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

@aidenhadisi/doublylinkedlist

v1.5.0

Published

A doubly linked list library for js.

Downloads

10

Readme

DoublyLinkedList

A lightweight doubly linked list library for JavaScript.

A Doubly Linked List library that allows insertion and deletion both at the end and the front of the list in constant time complexity. The library also provides pointers to both front and end of the list which allows easy traversal in either direction.

Install

$ npm install @aidenhadisi/doublylinkedlist

Or using yarn

$ yarn add @aidenhadisi/doublylinkedlist

Usage

Adding Elements

import LinkedList from "@aidenhadisi/doublylinkedlist";

//Specify data type you want to store in the list, for example number:
let list = new LinkedList<number>();

//Add an element to the end of the list
list.push(3)

//Add an element to the front of the list
list.unshift(5)

//Prints 2
console.log(list.length)

Removing Elements

//Remove an element from the end of the list
let element = list.pop();

//Remove an element from the front of the list
let element = list.shift();

Accessing Data

let element = list.pop();

// Value stored in the node
element.val;

// A pointer to the next element
element.next;

// A pointer to the previous element
element.prev;

Traversal

Traverse the list from the front:

let head = list.head;

while (head !== null) {
	console.log(head.val);
	head = head.next;
}

Traverse the list from the end:

let tail = list.tail;

while (tail !== null) {
	console.log(tail.val);
	tail = tail.prev;
}

Length

You can get the size of the list at any point using the .length getter. This property is stored and not computed; therefore, it has a constant time complexity.

//Get the size of the list
console.log(list.length);

toArray()

You can get a copy of the linkedlist in array format by calling the toArray() method. Note that time complexity of this method is O(n) as it needs to traverse through entire list.

let array = list.toArray();