Class DoublyLinkedList<E, R>

  1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
  2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
  3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
  4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.

Type Parameters

  • E = any

  • R = any

Hierarchy

Accessors

  • get first(): undefined | E
  • Time Complexity: O(1) Space Complexity: O(1)

    The get first function returns the first node in a doubly linked list, or undefined if the list is empty.

    Returns undefined | E

    The method get first() returns the first node of the doubly linked list, or undefined if the list is empty.

  • get last(): undefined | E
  • Time Complexity: O(1) Space Complexity: O(1)

    The get last function returns the last node in a doubly linked list, or undefined if the list is empty.

    Returns undefined | E

    The method get last() returns the last node of the doubly linked list, or undefined if the list is empty.

  • get size(): number
  • The function returns the size of an object.

    Returns number

    The size of the object, which is a number.

  • get toElementFn(): undefined | ((rawElement) => E)
  • The function returns the _toElementFn property, which is a function that converts a raw element to a specific type.

    Returns undefined | ((rawElement) => E)

    The function get toElementFn() is returning either a function that takes a raw element rawElement of type R and returns an element E, or undefined if no function is assigned to _toElementFn.

Methods

  • Time Complexity: O(n) Space Complexity: O(1)

    The function is an implementation of the Symbol.iterator method that returns an IterableIterator.

    Parameters

    • Rest ...args: any[]

      The args parameter in the code snippet represents a rest parameter. It allows the function to accept any number of arguments as an array. In this case, the args parameter is used to pass any number of arguments to the _getIterator method.

    Returns IterableIterator<E>

  • The function returns an iterator that iterates over the values of a linked list.

    Returns IterableIterator<E>

  • Time Complexity: O(1) or O(n) Space Complexity: O(1)

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

    Parameters

    • existingValueOrNode: E | 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.

  • Time Complexity: O(n) Space Complexity: O(1)

    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.

    • value: E

      The value 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.

  • Time Complexity: O(1) or O(n) Space Complexity: O(1)

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

    Parameters

    • existingValueOrNode: E | 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.

  • Time Complexity: O(n) Space Complexity: O(1)

    The at function returns the value at a specified index in a linked list, or undefined 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 undefined.

  • Time Complexity: O(1) Space Complexity: O(1)

    The clear function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.

    Returns void

  • Time Complexity: O(n) Space Complexity: O(n)

    The clone function creates a new instance of the DoublyLinkedList class with the same values as the original list.

    Returns DoublyLinkedList<E, R>

    The clone() method is returning a new instance of the DoublyLinkedList class, which is a copy of the original list.

  • Time Complexity: O(1) or O(n) Space Complexity: O(1)

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

    Parameters

    • valOrNode: undefined | E | 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.

  • Time Complexity: O(n) Space Complexity: O(1)

    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 boolean

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

  • Time Complexity: O(n) Space Complexity: O(1)

    The every function checks if every element in the array satisfies a given predicate.

    Parameters

    • predicate: ElementCallback<E, R, boolean, DoublyLinkedList<E, R>>

      The predicate parameter is a callback function that takes three arguments: the current element being processed, its index, and the array it belongs to. It should return a boolean value indicating whether the element satisfies a certain condition or not.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the predicate function. If thisArg is provided, it will be passed as the this value to the predicate function. If thisArg is

    Returns boolean

    The every method is returning a boolean value. It returns true if every element in the array satisfies the provided predicate function, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The filter function creates a new DoublyLinkedList by iterating over the elements of the current list and applying a callback function to each element, returning only the elements for which the callback function returns true.

    Parameters

    • callback: ElementCallback<E, R, boolean, DoublyLinkedList<E, R>>

      The callback parameter is a function that will be called for each element in the DoublyLinkedList. It takes three arguments: the current element, the index of the current element, and the DoublyLinkedList itself. The callback function should return a boolean value indicating whether the current element should be included

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callback function. If thisArg is provided, it will be passed as the this value to the callback function. If thisArg is

    Returns DoublyLinkedList<E, R>

    The filter method is returning a new DoublyLinkedList object that contains the elements that pass the filter condition specified by the callback function.

  • Time Complexity: O(n) Space Complexity: O(1)

    The find function iterates over the elements of an array-like object and returns the first element that satisfies the provided callback function.

    Parameters

    • callbackfn: ElementCallback<E, R, boolean, DoublyLinkedList<E, R>>

      The callbackfn parameter is a function that will be called for each element in the array. It takes three arguments: the current element being processed, the index of the current element, and the array itself. The function should return a boolean value indicating whether the current element matches the desired condition.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callbackfn function. If thisArg is provided, it will be passed as the this value to the callbackfn function. If thisArg @returns The findmethod returns the first element in the array that satisfies the provided callback function. If no element satisfies the callback function,undefined` is returned.

    Returns undefined | E

  • Time Complexity: O(n) Space Complexity: O(1)

    The findBackward 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 undefined if no value satisfies the callback.

    Parameters

    • callback: ((value) => 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.

        • (value): boolean
        • Parameters

          • value: E

          Returns boolean

    Returns undefined | E

    The method findBackward 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 undefined.

  • Time Complexity: O(n) Space Complexity: O(1)

    The forEach function iterates over each element in an array-like object and calls a callback function for each element.

    Parameters

    • callbackfn: ElementCallback<E, R, void, DoublyLinkedList<E, R>>

      The callbackfn parameter is a function that will be called for each element in the array. It takes three arguments: the current element being processed, the index of the current element, and the array that forEach was called upon.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callbackfn function. If thisArg is provided, it will be passed as the this value to the callbackfn function. If `thisArg

    Returns void

  • Time Complexity: O(n) Space Complexity: O(1)

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

    Parameters

    • value: undefined | E

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

    Returns undefined | DoublyLinkedListNode<E>

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

  • Time Complexity: O(n) Space Complexity: O(1)

    The function getNodeAt returns the node at a given index in a doubly linked list, or undefined 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 undefined | 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 undefined.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function checks if a given element exists in a collection.

    Parameters

    • element: E

      The parameter "element" is of type E, which means it can be any type. It represents the element that we want to check for existence in the collection.

    Returns boolean

    a boolean value. It returns true if the element is found in the collection, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(1)

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

    Parameters

    • value: E

      The parameter value 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 value in the linked list. If the value is not found, it returns -1.

  • Time Complexity: O(1) Space Complexity: O(1)

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

    Returns boolean

    A boolean value is being returned.

  • The map function takes a callback function and returns a new DoublyLinkedList with the results of applying the callback to each element in the original list.

    Type Parameters

    • EM

    • RM

    Parameters

    • callback: ElementCallback<E, R, EM, DoublyLinkedList<E, R>>

      The callback parameter is a function that will be called for each element in the original DoublyLinkedList. It takes three arguments: current (the current element being processed), index (the index of the current element), and this (the original DoublyLinkedList). The callback function should return a value of type

    • Optional toElementFn: ((rawElement) => EM)

      The toElementFn parameter is an optional function that can be used to convert the raw element (RR) to the desired element type (T). It takes the raw element as input and returns the converted element. If this parameter is not provided, the raw element will be used as is.

        • (rawElement): EM
        • Parameters

          • rawElement: RM

          Returns EM

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. It is used to set the context or scope in which the callback function will be executed. If thisArg is provided, it will be used as the value of

    Returns DoublyLinkedList<EM, RM>

    a new instance of the DoublyLinkedList class with elements of type T and RR.

  • The pop() function removes and returns the value of the last element in a linked list.

    Returns undefined | E

    The method is returning the value of the removed node.

  • The push function adds a new element to the end of a doubly linked list.

    Parameters

    • element: E

      The "element" parameter represents the value that you want to add to the doubly linked list.

    Returns boolean

    The push method is returning a boolean value, true.

  • Time Complexity: O(n) Space Complexity: O(1)

    The reduce function iterates over the elements of an array-like object and applies a callback function to reduce them into a single value.

    Type Parameters

    • U

    Parameters

    • callbackfn: ReduceElementCallback<E, R, U, DoublyLinkedList<E, R>>

      The callbackfn parameter is a function that will be called for each element in the array. It takes four arguments:

    • initialValue: U

      The initialValue parameter is the initial value of the accumulator. It is the value that the accumulator starts with before the reduction operation begins.

    Returns U

    The reduce method is returning the final value of the accumulator after iterating over all the elements in the array and applying the callback function to each element.

  • The shift() function removes and returns the value of the first element in a doubly linked list.

    Returns undefined | E

    The value of the removed node.

  • Time Complexity: O(n) Space Complexity: O(1)

    The "some" function checks if at least one element in a collection satisfies a given predicate.

    Parameters

    • predicate: ElementCallback<E, R, boolean, DoublyLinkedList<E, R>>

      The predicate parameter is a callback function that takes three arguments: value, index, and array. It should return a boolean value indicating whether the current element satisfies the condition.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as the this value when executing the predicate function. If thisArg is provided, it will be passed as the this value to the predicate function. If `thisArg

    Returns boolean

    a boolean value. It returns true if the predicate function returns true for any element in the collection, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The toArray function converts a linked list into an array.

    Returns E[]

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

  • Time Complexity: O(n) Space Complexity: O(n)

    The toReversedArray function converts a doubly linked list into an array in reverse order.

    Returns E[]

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

  • The unshift function adds a new element to the beginning of a doubly linked list.

    Parameters

    • element: E

      The "element" parameter represents the value of the element that you want to add to the beginning of the doubly linked list.

    Returns boolean

    The unshift method is returning a boolean value, true.

  • Time Complexity: O(n) Space Complexity: O(n)

    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, any>

    The fromArray function returns a DoublyLinkedList object.

Generated using TypeDoc