Skip to content

SingleLinkedList<T> and DoubleLinkedList<T> ​

Guide: /guide/data-structures/linked-list

Generic Types ​

T - type of collection elements

Implements interfaces ​

ILinkedList ​

ILinearStorage ​

ILinearStorageRA ​

Methods ​

constructor(capacity?: number): IlinkedList<T> ​

Creates empty instance

Params: ​
NameTypeRequiredDefaultDescription
capacitynumber-Number.MAX_VALUEMax capacity of list
(0 < capacity < Number.MAX_VALUE)



peek(): T ​

Returns value from top of list

Throws: CollectionIsEmptyException when list is empty ​



pop(): T ​

Removes item from list end (head element) and returns its value

Throws: CollectionIsEmptyException when list is empty ​



push(value: T): void ​

Add value to top of list

Params: ​
NameTypeRequiredDefaultDescription
valueT+-
Throws: CollectionIsFullException when there is no space available ​



has(value: T): boolean ​

Check is list has given value

Params: ​
NameTypeRequiredDefaultDescription
valueT+-



peekFromStart(): T ​

Get first element of list (tail)

Throws: CollectionIsEmptyException when list is empty ​



peekByIndex(index: number): T ​

Get element by given index from list start

Params: ​
NameTypeRequiredDefaultDescription
indexnumber+-0 <= index <= list.length - 1
Throws: CollectionIsEmptyException when list is empty ​
Throws: IndexOutOfBoundsException when index is out of range ​



unshift(value: T): void ​

Add new node into list start (node becomes tail)

Throws: CollectionIsFullException when there is no space available ​
Params: ​
NameTypeRequiredDefaultDescription
valueT+-



pushFromIndex(value: T, fromIndex: number): void ​

Add new node into list by index

Params: ​
NameTypeRequiredDefaultDescription
valueT+-
fromIndexnumber+-0 <= index <= list.length - 1
Throws: CollectionIsFullException when there is no space available ​
Throws: IndexOutOfBoundsException when index is out of range ​



shift(): T ​

Remove node from list start (tail element) and get its value

Throws: CollectionIsEmptyException when list is empty ​



deleteFromIndex(fromIndex: number): T ​

Remove node from list by index

Params: ​
NameTypeRequiredDefaultDescription
fromIndexnumber+-0 <= index <= list.length - 1
Throws: CollectionIsEmptyException when list is empty ​



pushFromArray(elements: Array<T>): void ​

Add elements from array collection in order from start

Params: ​
NameTypeRequiredDefaultDescription
elementsArray<T>+-
Throws: CollectionIsFullException when there is no space available ​



getAsArray(): Array<T> ​

Convert linked list into array collection in order from start

Params: ​
NameTypeRequiredDefaultDescription
elementsArray<T>+-



clear(): void ​

Remove all elements from list



isEmpty(): boolean ​

Check is list has any value, returns true if list is empty



isFull(): boolean ​

Check is list length exceed max capacity



length(): number ​

Get list size





IterableSingleLinkedList<T> ​

Guide: /guide/data-structures/linked-list

Generic Types ​

T - type of collection elements

Extends ​

Extends SingleLinkedList ​

Implements interfaces ​

ILinkedList ​

ILinearStorage ​

ILinearStorageRA ​

IIterable ​

Methods ​

constructor(capacity?: number): IlinkedList<T> ​

Creates empty instance

Params: ​
NameTypeRequiredDefaultDescription
capacitynumber-Number.MAX_VALUEMax capacity of list
(0 < capacity < Number.MAX_VALUE)



iterator(fromIndex?: number): IIterator<T> ​

Params: ​
NameTypeRequiredDefaultDescription
fromIndexnumber+-0 <= index <= list.length - 1
Throws: CollectionIsEmptyException when list is empty ​
Throws: IndexOutOfBoundsException when index is out of range ​



Methods ​

current(): T ​

Get current iterator element data

next(): T ​

Move to next element and get its data

Throws IllegalStateException when there is no next element ​



hasNext(): boolean ​

Check is there next element available



IterableDoubleLinkedList<T> ​

Guide: /guide/data-structures/linked-list

Generic Types ​

T - type of collection elements

Extends ​

Extends DoubleLinkedList ​

Implements interfaces ​

ILinkedList ​

ILinearStorage ​

ILinearStorageRA ​

IIterable ​

IBiDirectIterable ​

Methods ​

constructor(capacity?: number): IlinkedList<T> ​

Creates empty instance

Params: ​
NameTypeRequiredDefaultDescription
capacitynumber-Number.MAX_VALUEMax capacity of list
(0 < capacity < Number.MAX_VALUE)



iterator(fromIndex?: number): IBiDirectIterator<T> ​

Params: ​
NameTypeRequiredDefaultDescription
fromIndexnumber+-0 <= index <= list.length - 1
Throws: CollectionIsEmptyException when list is empty ​
Throws: IndexOutOfBoundsException when index is out of range ​



Methods ​

current(): T ​

Get current iterator element data

next(): T ​

Move to next element and get its data

Throws IllegalStateException when there is no next element ​



hasNext(): boolean ​

Check is there next element available

prev(): T ​

Move to prev element and get its data

Throws IllegalStateException when there is no prev element ​



hasPrev(): boolean ​

Check is there next element available



MIT Licensed