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

dsa-with-javascript

v1.0.4

Published

dsa library in js

Downloads

15

Readme

DSA With JavaScript

dsa-with-javascript is DSA library written in javascript and provides basic data structures like Stack,Queue and Linked List along with some sorting and searching algorithms

Installation

Use the package manager npm to install dsa-with-javascript.

npm install dsa-with-javascript

Usage

Available data structures

1.Stack

//Stack uses Linked-List inside
const {Stack} = require('dsa-with-javascript')

const stack = new Stack() // Create a new instance of class Stack
stack.push(10) // Add new element in stack
stack.pop() //Pops the last element from stack
stack.top() //Returns the top element
stack.isEmpty() //Returns true is stack is empty else false
stack.show() // Returns the stack

2.Queue

//Queue uses Linked-List inside
const {Queue} = require('dsa-with-javascript')

const queue = new Queue() // Create a new instance of class Queue
queue.push(10) // Add new element in queue
queue.pop() //Pops the first element from queue
queue.top() //Returns the top element
queue.isEmpty() //Returns true is queue is empty else false
queue.show() // Returns the queue

3.Linked List

const {LinkedList} = require('dsa-with-javascript')

// Create a new instance of class LinkedList
// new LinkedList() creates head with null value
// new LinkedList(10) creates linked list with 1 node with data = 10
const list = new LinkedList()
list.createNew(20) //Adds new node to the list with given value(20)
list.size() //Returns the size of the linked list
list.getFirst() //Returns the data of first node of the linked list
list.getLast() //Returns the data of last node of the linked list
list.clear() //Clears the linked list (assigns head = null)
list.show() //Returns an array containing data of all nodes of linked list

Available algorithms

1.Binary Search

const {BinarySearch} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
BinarySearch(arr,5) //The BinarySearch function takes two arguments 1.The array and 2.Key

The BinarySearch function expects a sorted array as input, If not given the array is sorted by the function. The result is the index of the key element if found (of sorted array) else -1 if not found

2.Linear Search

const {LinearSearch} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
LinearSearch(arr,5) //The LinearSearch function takes two arguments 1.The array and 2.Key

The LinearSearch function returns the index of element if found otherwise -1 if not found

3.BubbleSort

const {BubbleSort} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
BubbleSort(arr) //Returns the sorted array in ascending order
BubbleSort(arr,-1) //Returns the sorted array in descending order

4.InsertionSort

const {InsertionSort} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
InsertionSort(arr) //Returns the sorted array in ascending order
InsertionSort(arr,-1) //Returns the sorted array in descending order

5.MergeSort

const {MergeSort} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
MergeSort(arr) //Returns the sorted array in ascending order
MergeSort(arr,-1) //Returns the sorted array in descending order

6.QuickSort

const {QuickSort} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
QuickSort(arr) //Returns the sorted array in ascending order
QuickSort(arr,-1) //Returns the sorted array in descending order

7.SelectionSort

const {SelectionSort} = require('dsa-with-javascript')
let arr = [1,2,3,4,5]
SelectionSort(arr) //Returns the sorted array in ascending order
SelectionSort(arr,-1) //Returns the sorted array in descending order

8.BreadthFirstSearch

const {BreadthFirstSearch} = require('dsa-with-javascript')
graph = {
  A: ["B", "C"],
  B: ["A", "D", "E"],
  C: ["A", "F"],
  D: ["B"],
  E: ["B", "F"],
  F: ["C", "E"],
};
BreadthFirstSearch(graph, "A") //Takes two arguments - Graph and the starting node and returns an array of traversed nodes with bfs

9.DepthFirstSearch

const {DepthFirstSearch} = require('dsa-with-javascript')
graph = {
  A: ["B", "C"],
  B: ["A", "D", "E"],
  C: ["A", "F"],
  D: ["B"],
  E: ["B", "F"],
  F: ["C", "E"],
};
DepthFirstSearch(graph, "A") //Takes two arguments - Graph and the starting node and returns an array of traversed nodes with dfs

Contributing

Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.

This library is just a project created by Moh1tsingh and is not intended for professional use.