@anorcle/dsa
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Data Structures and Algorithms For Web

Data Structures and Algorithms are highly useful for development of complex features in any Application. Here in this project we are targeting to implement most of the important and useful Data Structures and Algorithms for web Developers.

issues License Tweet Website GitHub

List of Implemented Data Structures

Installation

npm i @anorcle/dsa

Import

ECMAScript Modules

Import Everything

import * as dsa from '@anorcle/dsa';

Import Only Required Modules

import { AVL, BST, Deque, LinkedList, PriorityQueue, Queue, Set, Stack } from '@anorcle/dsa';

CommonJS

Import Everything

const dsa = require('@anorcle/dsa')

Import Only Required Modules

const { AVL, BST, Deque, LinkedList, PriorityQueue, Queue, Set, Stack } = require('@anorcle/dsa')

Examples

Max Heap

A Max Heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node.

TypeScript
import { PriorityQueue } from "@anorcle/dsa";

// compare function for Max Heap
const compare = (a: number, b: number): -1 | 0 | 1 => {
    if (a < b)
        return -1;
    if (a > b)
        return +1;
    return 0;
};

// create new Priority Queue of Numbers
const pq = new PriorityQueue<number>(compare);

pq.push(3);
pq.push(1);
pq.push(100);

console.log(pq.front) // 100

// remove the top element from priority queue and return it
pq.pop()
JavaScript
import { PriorityQueue } from "@anorcle/dsa";

// compare function for Max Heap
const compare = (a, b) => {
    if (a < b)
        return -1;
    if (a > b)
        return +1;
    return 0;
};

// create new Priority Queue of Numbers
const pq = new PriorityQueue(compare);
pq.push(3);
pq.push(1);
pq.push(100);
console.log(pq.front); // 100

// remove the top element from priority queue and return it
pq.pop();

Min Heap

A Min Heap is a complete binary tree in which the value in each internal node is smaller than or equal to the values in the children of that node.

TypeScript
import { PriorityQueue } from "@anorcle/dsa";

// compare function for Min Heap
const compare = (a: number, b: number): -1 | 0 | 1 => {
    if (a < b)
        return +1;
    if (a > b)
        return -1;
    return 0;
};

// create new Priority Queue of Numbers
const pq = new PriorityQueue<number>(compare);

pq.push(3);
pq.push(1);
pq.push(100);

console.log(pq.front) // 1

// remove the top element from priority queue and return it
pq.pop()
JavaScript
import { PriorityQueue } from "@anorcle/dsa";

// compare function for Min Heap
const compare = (a, b) => {
    if (a < b)
        return +1;
    if (a > b)
        return -1;
    return 0;
};

// create new Priority Queue of Numbers
const pq = new PriorityQueue(compare);
pq.push(3);
pq.push(1);
pq.push(100);
console.log(pq.front); // 1

// remove the top element from priority queue and return it
pq.pop();

Stack

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).

import { Stack } from "@anorcle/dsa";

const stack = new Stack<number>();
stack.push(3);
stack.push(1);
stack.push(100);

console.log(stack.top) // 100

// Remove Top Element from stack
stack.pop()

console.log(stack.top) // 1

Queue

A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO)

import { Queue } from "@anorcle/dsa";

const queue = new Queue<number>();
queue.push(3);
queue.push(1);
queue.push(100);

console.log(queue.front) // 3

// Remove First Element from Queue
queue.pop()

console.log(queue.front) // 1

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.00

Package Sidebar

Install

npm i @anorcle/dsa

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

72.1 kB

Total Files

53

Last publish

Collaborators

  • jhasuraj01