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:
Name | Type | Required | Default | Description |
---|---|---|---|---|
capacity | number | - | Number.MAX_VALUE | Max capacity of list (0 < capacity < Number.MAX_VALUE) |
peek(): T
Returns value from top of list
CollectionIsEmptyException
when list is empty
Throws: pop(): T
Removes item from list end (head element) and returns its value
CollectionIsEmptyException
when list is empty
Throws: push(value: T): void
Add value to top of list
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
CollectionIsFullException
when there is no space available
Throws: has(value: T): boolean
Check is list has given value
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
peekFromStart(): T
Get first element of list (tail)
CollectionIsEmptyException
when list is empty
Throws: peekByIndex(index: number): T
Get element by given index from list start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
index | number | + | - | 0 <= index <= list.length - 1 |
CollectionIsEmptyException
when list is empty
Throws: IndexOutOfBoundsException
when index is out of range
Throws: unshift(value: T): void
Add new node into list start (node becomes tail)
CollectionIsFullException
when there is no space available
Throws: Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
pushFromIndex(value: T, fromIndex: number): void
Add new node into list by index
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - | |
fromIndex | number | + | - | 0 <= index <= list.length - 1 |
CollectionIsFullException
when there is no space available
Throws: IndexOutOfBoundsException
when index is out of range
Throws: shift(): T
Remove node from list start (tail element) and get its value
CollectionIsEmptyException
when list is empty
Throws: deleteFromIndex(fromIndex: number): T
Remove node from list by index
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fromIndex | number | + | - | 0 <= index <= list.length - 1 |
CollectionIsEmptyException
when list is empty
Throws: pushFromArray(elements: Array<T>): void
Add elements from array collection in order from start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
elements | Array<T> | + | - |
CollectionIsFullException
when there is no space available
Throws: getAsArray(): Array<T>
Convert linked list into array collection in order from start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
elements | Array<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
SingleLinkedList
Extends Implements interfaces
ILinkedList
ILinearStorage
ILinearStorageRA
IIterable
Methods
constructor(capacity?: number): IlinkedList<T>
Creates empty instance
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
capacity | number | - | Number.MAX_VALUE | Max capacity of list (0 < capacity < Number.MAX_VALUE) |
iterator(fromIndex?: number): IIterator<T>
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fromIndex | number | + | - | 0 <= index <= list.length - 1 |
CollectionIsEmptyException
when list is empty
Throws: IndexOutOfBoundsException
when index is out of range
Throws: Methods
current(): T
Get current iterator element data
next(): T
Move to next element and get its data
IllegalStateException
when there is no next element
Throws hasNext(): boolean
Check is there next element available
IterableDoubleLinkedList<T>
Guide: /guide/data-structures/linked-list
Generic Types
T
- type of collection elements
Extends
DoubleLinkedList
Extends Implements interfaces
ILinkedList
ILinearStorage
ILinearStorageRA
IIterable
IBiDirectIterable
Methods
constructor(capacity?: number): IlinkedList<T>
Creates empty instance
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
capacity | number | - | Number.MAX_VALUE | Max capacity of list (0 < capacity < Number.MAX_VALUE) |
iterator(fromIndex?: number): IBiDirectIterator<T>
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fromIndex | number | + | - | 0 <= index <= list.length - 1 |
CollectionIsEmptyException
when list is empty
Throws: IndexOutOfBoundsException
when index is out of range
Throws: Methods
current(): T
Get current iterator element data
next(): T
Move to next element and get its data
IllegalStateException
when there is no next element
Throws hasNext(): boolean
Check is there next element available
prev(): T
Move to prev element and get its data
IllegalStateException
when there is no prev element
Throws hasPrev(): boolean
Check is there next element available