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

@tekksunn/cs-linked-lists

v1.0.1

Published

Computer Science: Linked Lists demonstration.

Downloads

119

Readme

Computer Science | Linked Lists

Make & Leave Project - Static Badge

About

A demonstration of what linked lists can do using JavaScript.

Installation

To use this linked list, simply include the LinkedList class in your JavaScript code.

npm install @tekksunn/cs-linked-lists

Linked List

This is a simple implementation of a Linked List in JavaScript. It provides various methods for interacting with the list, such as adding, removing, finding, and displaying nodes.

Features

The linked list includes the following methods:

  • append(value): Adds a new node with the specified value to the end of the list.
  • prepend(value): Adds a new node with the specified value to the beginning of the list.
  • pop(): Removes the last node in the list.
  • find(value): Finds the first node that matches the specified value and returns it.
  • at(index): Returns the node at the specified index.
  • contains(value): Checks if a node with the specified value exists in the list.
  • size: Gets the number of nodes in the list.
  • tail: Gets the last node in the list.
  • toString(): Converts the list into a string representation.
  • remove(value): Removes the first node that matches the specified value.
  • toArray(): Returns an array containing all the values from the linked list.

Usage

Create a new Linked List:

const list = new LinkedList();

Append a node to the list:

list.append(10); // Adds a node with value 10 to the end of the list

Prepend a node to the list:

list.prepend(5); // Adds a node with value 5 to the beginning of the list

Get the size of the list:

console.log(list.size); // Gets the size of the list (number of nodes)

Get the tail (last node):

console.log(list.tail); // Gets the last node in the list

Access a node by index:

console.log(list.at(0)); // Returns the node at index 0 (first node)

Check if the list contains a value:

console.log(list.contains(10)); // Returns true if the list contains the value 10

Remove the last node:

list.pop(); // Removes the last node from the list

Remove a specific value from the list:

list.remove(10); // Removes the first node with value 10

Find a node by its value:

console.log(list.find(5)); // Returns the node with value 5

Convert the list to a string:

console.log(list.toString()); // Returns a string representation of the list

Convert the list to an array:

console.log(list.toArray()); // Returns an array with all values in the list

Example

Here is a full example showing how the linked list works:

const list = new LinkedList();

list.append(10);
list.append(20);
list.prepend(5);

console.log(list.size()); // 3
console.log(list.toString()); // "( 5 ) -> ( 10 ) -> ( 20 ) -> null"
console.log(list.at(1)); // Node with value 10

list.pop();
console.log(list.toString()); // "( 5 ) -> ( 10 ) -> null"

list.remove(10);
console.log(list.toString()); // "( 5 ) -> null"

console.log(list.contains(5)); // true
console.log(list.contains(10)); // false

console.log(list.find(5)); // Node with value 5
console.log(list.find(10)); // null

console.log(list.toArray()); // [5]

Contributing

Feel free to fork this project and create a pull request if you'd like to contribute. Please make sure to write tests for any new features you add.

License

This project is open source and available under the MIT License.