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

data-structures-package

v1.0.3

Published

A data structures package including Stack, Queue, Linked List, and Tree

Downloads

298

Readme

🌟 Data Structures in JavaScript

A lightweight JavaScript library that provides essential data structures such as Stack, Queue, Linked List, and Tree (Arbre). This package simplifies the use of these data structures with clean APIs to help developers implement them in their projects effortlessly.


📦 Installation

You can install this package using npm or pnpm:

# Using npm
npm install data-structures-package

# Using pnpm
pnpm install data-structures-package

🚀 Usage

This package provides simple, intuitive APIs to work with common data structures like Stack, Queue, Linked List, and Tree.

# Stack
const { Stack } = require('data-structures-package');

const stack = new Stack();
stack.push(5);
stack.push(10);
console.log(stack.pop()); // Output: 10
console.log(stack.peek()); // Output: 5
# Queue
const { Queue } = require('data-structures-package');

const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // Output: 1
console.log(queue.peek()); // Output: 2

# Linked List

const { LinkedList } = require('data-structures-package');

const list = new LinkedList();
list.append(10);
list.append(20);
console.log(list.toArray()); // Output: [10, 20]
list.remove(10);
console.log(list.toArray()); // Output: [20]
list.append(10);
list.append(30);
console.log(list.display()); // Output : 20 -> 10 -> 30
# Tree (Arbre)

const { Tree } = require('data-structures-package');

const tree = new Tree(); // Root node
tree.addChild(2);
tree.addChild(3);
console.log(tree.inOrder()); // Output: [1, 2, 3]

🛠 API Reference

Stack

  • push(value): Adds a value to the stack.
  • pop(): Removes the top value from the stack and returns it. Returns null if the stack is empty.
  • peek(): Returns the top value of the stack without removing it.
  • toString(): Returns an array representation of the stack.
  • isEmpty(): Returns true if the stack is empty, otherwise returns false.

Queue

  • enqueue(value): Adds a value to the front of the queue.
  • dequeue(): Removes the last value from the queue and returns it. Returns null if the queue is empty.
  • peek(): Returns the last value in the queue without removing it.
  • isEmpty(): Returns true if the queue is empty, otherwise returns false.

LinkedList

  • append(value): Adds a value to the end of the linked list.
  • prepend(value): Adds a value to the beginning of the linked list.
  • find(value): Finds and returns the value and position of a node in the linked list. Returns null if the value is not found.
  • remove(value): Removes the node with the specified value from the list.
  • toArray(): Converts the linked list into an array of nodes.
  • display(): Returns a string representation of the linked list in the form value1 -> value2 -> value3.

Tree (Binary Search Tree)

  • addChild(value): Adds a new node to the tree at the correct position based on its value.
  • preOrder(): Traverses the tree in pre-order (node → left → right).
  • inOrder(): Traverses the tree in in-order (left → node → right).
  • postOrder(): Traverses the tree in post-order (left → right → node).

🤝 Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check the issues page if you want to contribute.

Steps to Contribute:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature-branch.
  3. Make your changes and commit them: git commit -m 'Add a new feature'.
  4. Push to the branch: git push origin feature-branch.
  5. Submit a pull request.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


👤 Author

Ayyoub


🌟 Show Your Support

If you like this project, feel free to give it a star ⭐ on GitHub!
You can also share this repository with others who might find it useful.

Thank you for your support! 🙌