# Class DoublyLinkedList<E>

#### Type Parameters

- #### E = any

#### Hierarchy

- DoublyLinkedList
  - Deque

- Defined in src/data-structures/linked-list/doubly-linked-list.ts:51

#####
Index

### Constructors

constructor

### Properties

_head
_length
_tail

### Accessors

head
length
size
tail

### Methods

addFirst
addLast
clear
delete
deleteAt
filter
find
findLast
findNode
forEach
getAt
getNodeAt
indexOf
insertAfter
insertAt
insertBefore
isEmpty
map
peekFirst
peekLast
pollFirst
pollLast
pop
push
reduce
reverse
shift
toArray
toArrayReverse
unshift
fromArray

## Constructors

### constructor

- new DoublyLinkedList<E>(): DoublyLinkedList<E>

- The constructor initializes the linked list with an empty head, tail, and length.

  #### Type Parameters

  - #### E = any

  #### Returns DoublyLinkedList<E>

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:55

## Properties

### `Private` _head

_head: null | DoublyLinkedListNode<E>

- Defined in src/data-structures/linked-list/doubly-linked-list.ts:61

### `Private` _length

_length: number

- Defined in src/data-structures/linked-list/doubly-linked-list.ts:81

### `Private` _tail

_tail: null | DoublyLinkedListNode<E>

- Defined in src/data-structures/linked-list/doubly-linked-list.ts:71

## Accessors

### head

- get head(): null | DoublyLinkedListNode<E>

- #### Returns null | DoublyLinkedListNode<E>

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:63
- set head(value): void

- #### Parameters

  - ##### value: null | DoublyLinkedListNode<E>

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:67

### length

- get length(): number

- #### Returns number

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:83

### size

- get size(): number

- #### Returns number

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:225

### tail

- get tail(): null | DoublyLinkedListNode<E>

- #### Returns null | DoublyLinkedListNode<E>

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:73
- set tail(value): void

- #### Parameters

  - ##### value: null | DoublyLinkedListNode<E>

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:77

## Methods

### addFirst

- addFirst(val): void

- The addFirst function adds a new node with the given value to the beginning of a doubly linked list.

  #### Parameters

  - ##### val: E

    The `val` parameter represents the value of the new node that will be added to the beginning of the doubly linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:205

### addLast

- addLast(val): void

- The addLast function adds a new node with the given value to the end of the doubly linked list.

  #### Parameters

  - ##### val: E

    The value to be added to the linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:122

### clear

- clear(): void

- The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:395

### delete

- delete(valOrNode): boolean

- The `delete` function removes a node from a doubly linked list based on either the node itself or its value.

  #### Parameters

  - ##### valOrNode: E

    The `valOrNode` parameter can accept either a value of type `E` or a `DoublyLinkedListNode<E>` object.

  #### Returns boolean

  The `delete` method returns a boolean value. It returns `true` if the value or node was successfully deleted from the doubly linked list, and `false` if the value or node was not found in the list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:334
- delete(valOrNode): boolean

- The `delete` function removes a node from a doubly linked list based on either the node itself or its value.

  #### Parameters

  - ##### valOrNode: DoublyLinkedListNode<E>

    The `valOrNode` parameter can accept either a value of type `E` or a `DoublyLinkedListNode<E>` object.

  #### Returns boolean

  The `delete` method returns a boolean value. It returns `true` if the value or node was successfully deleted from the doubly linked list, and `false` if the value or node was not found in the list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:335

### deleteAt

- deleteAt(index): undefined | E

- The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.

  #### Parameters

  - ##### index: number

    The index parameter represents the position of the element that needs to be deleted in the data structure. It is of type number.

  #### Returns undefined | E

  The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:320

### filter

- filter(callback): DoublyLinkedList<E>

- The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the elements that satisfy the given callback function.

  #### Parameters

  - ##### callback: ((val) => boolean)

    The `callback` parameter is a function that takes a value of type `E` and returns a boolean value. It is used to determine whether a value should be included in the filtered list or not.

    - - (val): boolean

      - #### Parameters

        - ##### val: E

        #### Returns boolean

  #### Returns DoublyLinkedList<E>

  The filtered list, which is an instance of the DoublyLinkedList class.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:526

### find

- find(callback): null | E

- The `find` function iterates through a linked list and returns the first element that satisfies a given condition.

  #### Parameters

  - ##### callback: ((val) => boolean)

    A function that takes a value of type E as its parameter and returns a boolean value. This function is used to determine whether a particular value in the linked list satisfies a certain condition.

    - - (val): boolean

      - #### Parameters

        - ##### val: E

        #### Returns boolean

  #### Returns null | E

  The method `find` returns the first element in the linked list that satisfies the condition specified by the callback function. If no element satisfies the condition, it returns `null`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:408

### findLast

- findLast(callback): null | E

- The `findLast` function iterates through a linked list from the last node to the first node and returns the last value that satisfies the given callback function, or null if no value satisfies the callback.

  #### Parameters

  - ##### callback: ((val) => boolean)

    A function that takes a value of type E as its parameter and returns a boolean value. This function is used to determine whether a given value satisfies a certain condition.

    - - (val): boolean

      - #### Parameters

        - ##### val: E

        #### Returns boolean

  #### Returns null | E

  The method `findLast` returns the last value in the linked list that satisfies the condition specified by the callback function. If no value satisfies the condition, it returns `null`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:447

### findNode

- findNode(val): null | DoublyLinkedListNode<E>

- The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the node if found, otherwise it returns null.

  #### Parameters

  - ##### val: E

    The `val` parameter is the value that we want to search for in the doubly linked list.

  #### Returns null | DoublyLinkedListNode<E>

  The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val` is found in the linked list. If no such node is found, it returns `null`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:269

### forEach

- forEach(callback): void

- The `forEach` function iterates over each element in a linked list and applies a callback function to each element.

  #### Parameters

  - ##### callback: ((val, index) => void)

    The callback parameter is a function that takes two arguments: val and index. The val argument represents the value of the current node in the linked list, and the index argument represents the index of the current node in the linked list.

    - - (val, index): void

      - #### Parameters

        - ##### val: E

        - ##### index: number

        #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:491

### getAt

- getAt(index): undefined | E

- The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.

  #### Parameters

  - ##### index: number

    The index parameter is a number that represents the position of the element we want to retrieve from the list.

  #### Returns undefined | E

  The method is returning the value at the specified index in the linked list. If the index is out of bounds or the linked list is empty, it will return null.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:236

### getNodeAt

- getNodeAt(index): null | DoublyLinkedListNode<E>

- The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of range.

  #### Parameters

  - ##### index: number

    The `index` parameter is a number that represents the position of the node we want to retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.

  #### Returns null | DoublyLinkedListNode<E>

  The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the valid range of the linked list, otherwise it returns `null`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:253

### indexOf

- indexOf(val): number

- The function returns the index of the first occurrence of a given value in a linked list.

  #### Parameters

  - ##### val: E

    The parameter `val` is of type `E`, which means it can be any data type. It represents the value that we are searching for in the linked list.

  #### Returns number

  The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked list. If the value is not found, it returns -1.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:426

### insertAfter

- insertAfter(existingValueOrNode, newValue): boolean

- The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.

  #### Parameters

  - ##### existingValueOrNode: E

    The existing value or node in the doubly linked list after which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The value that you want to insert into the doubly linked list.

  #### Returns boolean

  The method returns a boolean value. It returns true if the insertion is successful, and false if the existing value or node is not found in the doubly linked list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:558
- insertAfter(existingValueOrNode, newValue): boolean

- The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.

  #### Parameters

  - ##### existingValueOrNode: DoublyLinkedListNode<E>

    The existing value or node in the doubly linked list after which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The value that you want to insert into the doubly linked list.

  #### Returns boolean

  The method returns a boolean value. It returns true if the insertion is successful, and false if the existing value or node is not found in the doubly linked list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:559

### insertAt

- insertAt(index, val): boolean

- The `insert` function inserts a value at a specified index in a doubly linked list.

  #### Parameters

  - ##### index: number

    The index parameter represents the position at which the new value should be inserted in the DoublyLinkedList. It is of type number.

  - ##### val: E

    The `val` parameter represents the value that you want to insert into the Doubly Linked List at the specified index.

  #### Returns boolean

  The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the index is out of bounds.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:291

### insertBefore

- insertBefore(existingValueOrNode, newValue): boolean

- The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.

  #### Parameters

  - ##### existingValueOrNode: E

    The existing value or node in the doubly linked list before which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The `newValue` parameter represents the value that you want to insert into the doubly linked list.

  #### Returns boolean

  The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the insertion fails.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:597
- insertBefore(existingValueOrNode, newValue): boolean

- The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.

  #### Parameters

  - ##### existingValueOrNode: DoublyLinkedListNode<E>

    The existing value or node in the doubly linked list before which the new value will be inserted. It can be either the value of the existing node or the existing node itself.

  - ##### newValue: E

    The `newValue` parameter represents the value that you want to insert into the doubly linked list.

  #### Returns boolean

  The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the insertion fails.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:598

### isEmpty

- isEmpty(): boolean

- The function checks if a variable has a length greater than zero and returns a boolean value.

  #### Returns boolean

  A boolean value is being returned.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:388

### map

- map<U>(callback): DoublyLinkedList<U>

- The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new DoublyLinkedList with the transformed values.

  #### Type Parameters

  - #### U

  #### Parameters

  - ##### callback: ((val) => U)

    The callback parameter is a function that takes a value of type E (the type of values stored in the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped DoublyLinkedList).

    - - (val): U

      - #### Parameters

        - ##### val: E

        #### Returns U

  #### Returns DoublyLinkedList<U>

  The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:509

### peekFirst

- peekFirst(): undefined | E

- The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.

  #### Returns undefined | E

  The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:213

### peekLast

- peekLast(): undefined | E

- The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.

  #### Returns undefined | E

  The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:221

### pollFirst

- pollFirst(): undefined | E

- The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.

  #### Returns undefined | E

  The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:178

### pollLast

- pollLast(): undefined | E

- The `pollLast()` function removes and returns the value of the last node in a doubly linked list.

  #### Returns undefined | E

  The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the list is empty, it returns null.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:150

### pop

- pop(): undefined | E

- The `pop()` function removes and returns the value of the last node in a doubly linked list.

  #### Returns undefined | E

  The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the list is empty, it returns null.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:131

### push

- push(val): void

- The push function adds a new node with the given value to the end of the doubly linked list.

  #### Parameters

  - ##### val: E

    The value to be added to the linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:105

### reduce

- reduce<U>(callback, initialValue): U

- The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a single value.

  #### Type Parameters

  - #### U

  #### Parameters

  - ##### callback: ((accumulator, val) => U)

    The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is used to perform a specific operation on each element of the linked list.

    - - (accumulator, val): U

      - #### Parameters

        - ##### accumulator: U

        - ##### val: E

        #### Returns U

  - ##### initialValue: U

    The `initialValue` parameter is the initial value of the accumulator. It is the starting point for the reduction operation.

  #### Returns U

  The `reduce` method is returning the final value of the accumulator after iterating through all the elements in the linked list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:548

### reverse

- reverse(): void

- The `reverse` function reverses the order of the elements in a doubly linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:475

### shift

- shift(): undefined | E

- The `shift()` function removes and returns the value of the first node in a doubly linked list.

  #### Returns undefined | E

  The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked list.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:159

### toArray

- toArray(): E[]

- The `toArray` function converts a linked list into an array.

  #### Returns E[]

  The `toArray()` method is returning an array of type `E[]`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:374

### toArrayReverse

- toArrayReverse(): E[]

- The `toArrayReverse` function converts a doubly linked list into an array in reverse order.

  #### Returns E[]

  The `toArrayReverse()` function returns an array of type `E[]`.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:462

### unshift

- unshift(val): void

- The unshift function adds a new node with the given value to the beginning of a doubly linked list.

  #### Parameters

  - ##### val: E

    The `val` parameter represents the value of the new node that will be added to the beginning of the doubly linked list.

  #### Returns void

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:187

### `Static` fromArray

- fromArray<E>(data): DoublyLinkedList<E>

- The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the given array.

  #### Type Parameters

  - #### E

  #### Parameters

  - ##### data: E[]

    The `data` parameter is an array of elements of type `E`.

  #### Returns DoublyLinkedList<E>

  The `fromArray` function returns a DoublyLinkedList object.

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:93

Generated using TypeDoc