JSPM

ds-in-js

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q27305F
  • License ISC

- Stack - Queue - Linked List - Tree - Graph - Hash Table

Package Exports

  • ds-in-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ds-in-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Basic Datastructures introduced in javascript

  • Stack
  • Queue
  • Linked List
  • Tree
  • Graph
  • Hash Table

Installation and Usage

npm install ds-in-js --save-dev

Stack:

const { Stack } = require("ds-in-js");

const stack = new Stack();
stack.push(1);
stack.push(2);
const data = stack.pop(); // 2
const top = stack.peek(); // 1

Queue:

const { Queue } = require("ds-in-js");

const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
const data = queue.dequeue(); // 1
const top = queue.peek(); // 2

Linked List

const { LinkedList } = require("ds-in-js");
const lList = new LinkedList([1, 2, 3]);
console.log(lList.getElementAtStart());

Binary Search Tree:

const { BST } = require("ds-in-js");

const bst = new BST();
bst.insert(2);
bst.insert(1);
const node = bst.search(1); // { data: 1, left: null, right: null }
bst.delete(1);

Graph

const { Graph } = require("ds-in-js");
const graph = new Graph();

/*
    a---b
    |  /    
    | /
    c
*/

graph.addVertex("a");
graph.addVertex("b");
graph.addVertex("c");

graph.addEdge("a", "c"); // add weight using graph.addEdge('a', 'c', 10)
graph.addEdge("c", "b");
graph.addEdge("a", "b");

const output = [];
graph.dfs("a", vertex => output.push(vertex.name)); // ['a', 'c', 'b']