Class DoublyLinkedList<T>

Type Parameters

  • T = any

Hierarchy

  • DoublyLinkedList

Constructors

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

    Type Parameters

    • T = any

    Returns DoublyLinkedList<T>

Properties

_head: any
_length: any
_tail: any

Accessors

  • get head(): null | DoublyLinkedListNode<T>
  • Returns null | DoublyLinkedListNode<T>

  • set head(value): void
  • Parameters

    Returns void

  • get length(): number
  • Returns number

  • get tail(): null | DoublyLinkedListNode<T>
  • Returns null | DoublyLinkedListNode<T>

  • set tail(value): void
  • Parameters

    Returns void

Methods

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

    Returns void

  • Parameters

    • valOrNode: T

    Returns boolean

  • Parameters

    Returns boolean

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

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

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

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

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

  • 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

    Returns void

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

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

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

  • Parameters

    • existingValueOrNode: T
    • newValue: T

    Returns boolean

  • Parameters

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

  • Parameters

    • existingValueOrNode: T
    • newValue: T

    Returns boolean

  • Parameters

    Returns boolean

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

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

  • 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

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

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

    Returns void

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

  • The toArray function converts a linked list into an array.

    Returns T[]

    The toArray() method is returning an array of type 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[].

  • 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

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

Generated using TypeDoc