1.0.3 • Published 4 years ago

structures-for-data.ts v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

data-structures.ts

A bunch of data structures like linked list, stack, queue and others

Install

$ npm i structures-for-data.ts

Usage:

import {LinkedList, Queue, Stack } from 'structures-for-data.ts'
let linkedList = new LinkedList<>();
let queue = new Queue<>();
let stack = new Stack<>();

Table of Contents

TOC

LinkedList

Function nameDescription
add (value: T, index: number) : voidAdds an value at specified index
addAllStartingAt (values: T[], index: number) : voidAdds all elements from values at LinkedList start at given index
addFirst (value: T) : voidAdds an value at the beginning of the LinkedList
addLast (value: T) : voidAdds an value at the end of the LinkedList
addFirstAll (values: T[]) : voidAdds all elements from values at at the beginning of the LinkedList
addLastAll (values: T[]) : voidAdds all elements from values at at the end of the LinkedList
clear() : voidRemoves all elements of LinkedList
get(index: number) : TReturns element of index of the LinkedList
getFirst() : TReturns the first element of the LinkedList
getIndex (value: any) : numberReturns index of value given of the LinkedList
getLast() : TReturns the last element of the LinkedList
remove (value: T) : booleanReturns an boolean indicating whether given value has been removed or not
removeFirst() :booleanReturns an boolean indicating whether first element has been removed or not
removeIndex (index: number) : booleanReturns an boolean indicating whether index of element given has been removed or not
removeMultiple (startIndex: number, quantity: number):booleanReturns an boolean indicating whether given values has been removed or not
removeLast() : booleanReturns an boolean indicating whether last element has been removed or not
show() : voidPrints all element of the LinkedList
toArray(): T[]Converts the LinkedList into an array

Usage:

import {LinkedList } from 'structures-for-data.ts'
let linkedList = new LinkedList<>();
add (value: T, index: number)
linkedList.add(2,6);
addAllStartingAt (values: T[], index: number)
linkedList.addAllStartingAt([1,2,3,4], 3);
addFirstAll (values: T[])
linkedList.addFirstAll([1,2,3,4]);
addLastAll (values: T[])
linkedList.addLastAll([1,2,3,4]);
clear()
linkedList.clear();
get(index: number)
linkedList.get(4);
getFirst()
linkedList.getFirst();
getIndex (value: any)
linkedList.getIndex(80);
getLast()
linkedList.getLast();
remove (value: T)
linkedList.remove(80);
removeFirst()
linkedList.removeFirst();
removeIndex (index: number)
linkedList.removeLast();
removeMultiple (startIndex: number, quantity: number)
linkedList.removeIndex(4);
removeLast()
linkedList.removeMultiple(0,4)
show()
linkedList.show()
toArray()
linkedList.toArray();