Data Structures package made by TypeScript.
$ npm i @ahmeds.gaafer/ts-data-structures
import { SinglyLinkedList } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the linked list
const arr = [1, 2, 3];
const list = new SinglyLinkedList<number>(arr);
list.push(1);
list.view();
// You can chain methods that does not return a value
list.popStart().pop().view(); // vaild
list.getHead().view(); // invalid
functions:
import { DoublyLinkedList } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the linked list
const arr = [1, 2, 3];
const list = new DoublyLinkedList<number>(arr);
list.push(1);
list.view();
// You can chain methods that does not return a value
list.popStart().pop().view(); // vaild
list.getHead().view(); // invalid
functions:
import { Queue } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the Queue
const arr = [1, 2, 3];
const queue = new Queue<number>(arr);
queue.enqueue(5);
queue.deqeue();
// You can chain methods that does not return a value
queue.enqueue(5).dequeue().view(); //vaild
queue.peak().view(); // invalid
functions:
import { Stack } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the Heap
const arr = [1, 2, 3];
const stack = new Stack<number>(arr);
stack.push(1);
// You can chain methods that does not return a value
stack.push(1).push(2).pop(); // vaild
stack.peak().push(1); // invalid
functions:
import { Heap } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the Heap
const arr = [1, 2, 3];
const maxHeapOptions = {
cmp: (a, b) => a < b;
}
const minHeapOptions = {
cmp: (a, b) => a > b;
}
// Heap type is set to number by default but you can change it
//min heap
const minHeap = new Heap(arr, minHeapOptions);
//max heap
const maxHeap = new Heap(arr, maxHeapOptions);
/// or
const maxHeap = new Heap<string>([], maxHeapOptions);
maxHeap.push(5);
// You can chain methods that does not return a value
minHeap.push(1).push(2); // vaild
minHeap.peak().push(1); // invalid
functions:
import { Graph } from "@ahmeds.gaafer/ts-data-structures";
//The graph can has 2 arguments that are set to false by default.
//The first argument is "isUniDirectional" if you set it to true the graph will be a directed graph.
//The second argument is "isWeighted" if you set it to true the graph will be weighted.
const g = new Graph(); // un-directed un-weighted graph
//or
const g = new Graph(true, false); // directed un-weighted graph.
//or
const g = new Graph(false, true); // un-directed weighted graph.
//or
const g = new Graph(true, true); // directed weighted graph
g.addVertex(1);
g.addVertex(2);
// You can chain methods that does not return a value
g.addVertex(1).addVertex(2); // valid
g.getNeighbors(1).addVertex(3); // invalid
g.removeVertex(5); // remove a non-existent vertex
// etc...
functions:
Any usage of the functions not mentioned in the functions above might lead to un-expected behavior and may lead to the functions throwing an error.
Generated using TypeDoc