@mkhstar/datastructures
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@mkhstar/datastructures

Popular data structures implemented in Typescript (Javascript)

NPM JavaScript Style Guide

Install

npm

$ npm install --save @mkhstar/datastructures

Linked List

Constructors

constructor

+ new LinkedList<E>(...initialItems: E[]): LinkedList<E>

description: Constructs a new linked list

Methods

[Symbol.iterator]

[Symbol.iterator](): Generator<E, void, unknown>

Returns: Generator<E, void, unknown>


add

add(...items: E[]): void

description appends the elements at the tail (end) of the linked list

Parameters:

Name Type Description
...items E[]

Returns: void


addFirst

addFirst(item: E): void

description Adds an element to the linked list at the head

Parameters:

Name Type Description
item E

Returns: void


addLast

addLast(item: E): void

description Adds an element to the tail of the linked list

Parameters:

Name Type Description
item E

Returns: void


clear

clear(): void

description Clears the linked list

Returns: void


getFirstElement

getFirstElement(): null | E

Returns: null | E

The first element of the linked list


getLastElement

getLastElement(): null | E

Returns: null | E

The last element of the linked list


indexOf

indexOf(index: number): null | E

Parameters:

Name Type Description
index number The index to look up

Returns: null | E


insertAt

insertAt(index: number, element: E): boolean

description inserts an element at the specified index

Parameters:

Name Type Description
index number
element E

Returns: boolean


removeAt

removeAt(index: number): boolean

description Removes an element at the specified index, returns true if an element was removed and false otherwise

Parameters:

Name Type
index number

Returns: boolean

boolean


removeElement

removeElement(element: E): boolean

description Removes an element that is equal to the element specified

Parameters:

Name Type Description
element E

Returns: boolean


removeElementWhere

removeElementWhere(test: TestLinkedListElement<E>): boolean

description Remove an element that satisfy the test function

Parameters:

Name Type Description
test TestLinkedListElement<E>

Returns: boolean


removeElements

removeElements(element: E): void

description Removes all elements that are equal to the element specified

Parameters:

Name Type Description
element E The element to look up

Returns: void


removeElementsWhere

removeElementsWhere(test: TestLinkedListElement<E>): void

description Removes all elements that satisfy the test function

Parameters:

Name Type Description
test TestLinkedListElement<E>

Returns: void


size

size(): number

Returns: number

The size of the linked list

Stack

Constructors

constructor

+ new Stack<E>(capacity?: number): Stack<E>

Methods

isEmpty

isEmpty(): boolean

description Is the stack empty?

Returns: boolean


peek

peek(): null | E

description Returns the element at the top of the stack

Returns: null | E


pop

pop(): null | E

description Removes an element from the top of the stack and return it

Returns: null | E


push

push(element: E): void

description Push an element to the stack

Parameters:

Name Type Description
element E

Returns: void

Queue

Constructors

constructor

+ new Queue<E>(capacity?: number): Queue<E>

description Default capacity is 50. If you try to add more than the capacity of the queue, an error will be thrown

Getters

isEmpty

isEmpty(): boolean

description Is the Queue empty

Returns: boolean


isFull

isFull(): boolean

description Is the Queue full

Returns: boolean

Methods

dequeue

dequeue(): null | E

description Remove an element from the queue and return it

Returns: null | E


enqueue

enqueue(element: E): void

description Add an element to the queue

Parameters:

Name Type Description
element E

Returns: void


peek

peek(): null | E

description Returns the element at the head of the queue

Returns: null | E

Tests

Tests will be written soon. But pull requests will be appreciated

Readme

Keywords

none

Package Sidebar

Install

npm i @mkhstar/datastructures

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

45.9 kB

Total Files

18

Last publish

Collaborators

  • mkhstar