# Deque | data-structure-typed
Documentation for data-structure-typed

# Class Deque<T>

#### Type Parameters

- #### T

#### Hierarchy

- DoublyLinkedList <T>
  - Deque

- Defined in src/data-structures/queue/deque.ts:12

#####
Index

### Constructors

constructor

### Accessors

head
length
tail

### Methods

clear
delete
deleteAt
filter
find
findLast
findNode
forEach
getAt
getNodeAt
indexOf
insertAfter
insertAt
insertBefore
map
pop
push
reduce
reverse
shift
toArray
toArrayReverse
unshift
fromArray

## Constructors

### constructor

- new Deque<T>(): Deque <T>

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

  #### Type Parameters

  - #### T

  #### Returns Deque <T>

  Inherited from DoublyLinkedList.constructor

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

## Accessors

### head

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

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

  Inherited from DoublyLinkedList.head

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

- #### Parameters

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

  #### Returns void

  Inherited from DoublyLinkedList.head

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

### length

- get length(): number

- #### Returns number

  Inherited from DoublyLinkedList.length

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

### tail

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

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

  Inherited from DoublyLinkedList.tail

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

- #### Parameters

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

  #### Returns void

  Inherited from DoublyLinkedList.tail

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

## Methods

### clear

- clear(): void

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

  #### Returns void

  Inherited from DoublyLinkedList.clear

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

### 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: T

    The `valOrNode` parameter can accept either a value of type `T` or a `DoublyLinkedListNode<T>` 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.

  Inherited from DoublyLinkedList.delete

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:279
- 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 <T>

    The `valOrNode` parameter can accept either a value of type `T` or a `DoublyLinkedListNode<T>` 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.

  Inherited from DoublyLinkedList.delete

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

### deleteAt

- deleteAt(index): undefined | T

- 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 | T

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

  Inherited from DoublyLinkedList.deleteAt

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

### filter

- filter(callback): DoublyLinkedList <T>

- 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 `T` 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: T

        #### Returns boolean

  #### Returns DoublyLinkedList <T>

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

  Inherited from DoublyLinkedList.filter

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

### find

- find(callback): null | T

- 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 T 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: T

        #### Returns boolean

  #### Returns null | T

  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`.

  Inherited from DoublyLinkedList.find

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

### findLast

- findLast(callback): null | T

- 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 T 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: T

        #### Returns boolean

  #### Returns null | T

  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`.

  Inherited from DoublyLinkedList.findLast

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

### findNode

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

- 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: T

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

  #### Returns null | DoublyLinkedListNode <T>

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

  Inherited from DoublyLinkedList.findNode

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

### 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: T

        - ##### index: number

        #### Returns void

  Inherited from DoublyLinkedList.forEach

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

### getAt

- getAt(index): undefined | T

- 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 | T

  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.

  Inherited from DoublyLinkedList.getAt

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

### getNodeAt

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

- 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 <T>

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

  Inherited from DoublyLinkedList.getNodeAt

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

### indexOf

- indexOf(val): number

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

  #### Parameters

  - ##### val: T

    The parameter `val` is of type `T`, 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.

  Inherited from DoublyLinkedList.indexOf

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

### 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: T

    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: T

    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.

  Inherited from DoublyLinkedList.insertAfter

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:495
- 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 <T>

    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: T

    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.

  Inherited from DoublyLinkedList.insertAfter

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

### 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: T

    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.

  Inherited from DoublyLinkedList.insertAt

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

### 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: T

    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: T

    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.

  Inherited from DoublyLinkedList.insertBefore

  - Defined in src/data-structures/linked-list/doubly-linked-list.ts:534
- 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 <T>

    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: T

    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.

  Inherited from DoublyLinkedList.insertBefore

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

### 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 T (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: T

        #### Returns U

  #### Returns DoublyLinkedList <U>

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

  Inherited from DoublyLinkedList.map

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

### pop

- pop(): undefined | T

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

  #### Returns undefined | T

  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.

  Inherited from DoublyLinkedList.pop

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

### 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: T

    The value to be added to the linked list.

  #### Returns void

  Inherited from DoublyLinkedList.push

  - 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: T

        #### 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.

  Inherited from DoublyLinkedList.reduce

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

### reverse

- reverse(): void

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

  #### Returns void

  Inherited from DoublyLinkedList.reverse

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

### shift

- shift(): undefined | T

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

  #### Returns undefined | T

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

  Inherited from DoublyLinkedList.shift

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

### toArray

- toArray(): T[]

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

  #### Returns T[]

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

  Inherited from DoublyLinkedList.toArray

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

### toArrayReverse

- toArrayReverse(): T[]

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

  #### Returns T[]

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

  Inherited from DoublyLinkedList.toArrayReverse

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

### 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: T

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

  #### Returns void

  Inherited from DoublyLinkedList.unshift

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

### `Static` fromArray

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

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

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### data: T[]

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

  #### Returns DoublyLinkedList <T>

  The `fromArray` function returns a DoublyLinkedList object.

  Inherited from DoublyLinkedList.fromArray

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

Generated using TypeDoc