Socket
Socket
Sign inDemoInstall

@mkhstar/datastructures

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mkhstar/datastructures

Data Structures for Javascript


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@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:
NameTypeDescription
...itemsE[]

Returns: void


addFirst

addFirst(item: E): void

description Adds an element to the linked list at the head

Parameters:
NameTypeDescription
itemE

Returns: void


addLast

addLast(item: E): void

description Adds an element to the tail of the linked list

Parameters:
NameTypeDescription
itemE

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:
NameTypeDescription
indexnumberThe index to look up

Returns: null | E


insertAt

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

description inserts an element at the specified index

Parameters:
NameTypeDescription
indexnumber
elementE

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:
NameType
indexnumber

Returns: boolean

boolean


removeElement

removeElement(element: E): boolean

description Removes an element that is equal to the element specified

Parameters:
NameTypeDescription
elementE

Returns: boolean


removeElementWhere

removeElementWhere(test: TestLinkedListElement<E>): boolean

description Remove an element that satisfy the test function

Parameters:
NameTypeDescription
testTestLinkedListElement<E>

Returns: boolean


removeElements

removeElements(element: E): void

description Removes all elements that are equal to the element specified

Parameters:
NameTypeDescription
elementEThe element to look up

Returns: void


removeElementsWhere

removeElementsWhere(test: TestLinkedListElement<E>): void

description Removes all elements that satisfy the test function

Parameters:
NameTypeDescription
testTestLinkedListElement<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:
NameTypeDescription
elementE

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:
NameTypeDescription
elementE

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

FAQs

Last updated on 21 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc