Options
All
• Public
• Public/Protected
• All

In computer science, a linked list is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration. source: www.thecodingdelight.com

### Complexity

Algorithm Average Worst case
Access `O(n)` `O(n)`
Search `O(n)` `O(n)`
Insert `O(1)` `O(1)`
Delete `O(1)` `O(1)`
- - -
Space `O(n)` `O(n)`

### Reference

``````import { LinkedList } from '@pencroff/ts-algorithms/dist/structure/linked';
const list = new LinkedList([1, 2, 3])``````

LinkedList implements `generic` doubly linked list

• Iterable<T>

## Constructors

### constructor

#### Parameters

• ##### Optional initArr: T[]

initial data as array

## Properties

_len: number

### Private comparator

comparator: ComparatorFn<T>

## Accessors

### length

• get length(): number

## Methods

### __@iterator

• __@iterator(): Iterator<T>

### backward

• backward(): Iterable<T>

### clear

• clear(): void

### find

• Find first node by value in LinkedList, used comparator function, linear search

Complexity: O(n)

### findLast

• Find last node by value in LinkedList, used comparator function, linear search

Complexity: O(n)

### has

• has(value: T): boolean

### insertAfter

• Insert value or node after node

Complexity: O(1)

### insertBefore

• Insert value or node before node

Complexity: O(1)

### insertFirst

• Insert value or node first

Complexity: O(1)

### insertLast

• Insert value or node last

Complexity: O(1)

### remove

• Remove node by reference or value from LinkedList

Complexity:

• remove(value: T) - O(n)

### removeFirst

• removeFirst(): boolean

### removeLast

• removeLast(): boolean

### toArray

• toArray(): T[]