Class SinglyLinkedList<NodeVal>

Type Parameters

  • NodeVal = any

Hierarchy

  • SinglyLinkedList

Constructors

Properties

_head: null | SinglyLinkedListNode<NodeVal>
_size: number
_tail: null | SinglyLinkedListNode<NodeVal>

Accessors

Methods

  • The filter function filters the elements of a singly linked list based on a given callback function.

    Parameters

    • callbackFn: ((data, index, list) => boolean)

      A callback function that takes three parameters: data, index, and list. It should return a boolean value indicating whether the current element should be included in the filtered list or not.

        • (data, index, list): boolean
        • Parameters

          Returns boolean

    • Optional reverse: boolean = false

      The reverse parameter is a boolean value that determines whether the filtered list should be reversed or not. If reverse is set to true, the filtered list will be in reverse order. If reverse is set to false or not provided, the filtered list will be in

    Returns SinglyLinkedList<{} | NodeVal>

    The filter method is returning a new SinglyLinkedList object.

  • The find function in TypeScript searches for a node in a singly linked list based on a given callback function and returns the value of the found node.

    Parameters

    • callbackFn: ((data, index, list) => boolean)

      A callback function that takes three parameters: data, index, and list. It returns a boolean value indicating whether the condition is met for a particular node in the linked list.

        • (data, index, list): boolean
        • Parameters

          Returns boolean

    Returns undefined | NodeVal

    The method find returns the NodeVal value of the first node in the linked list that satisfies the condition specified by the callbackFn function. If no node satisfies the condition, it returns undefined.

  • The findIndex function returns the index of the first node in a singly linked list that satisfies a given condition, or -1 if no such node is found.

    Parameters

    • callbackFn: ((data, index, list) => boolean)

      A callback function that takes three parameters: data, index, and list. It returns a boolean value indicating whether the condition is met for a particular node in the singly linked list.

        • (data, index, list): boolean
        • Parameters

          Returns boolean

    Returns number

    The method findIndex returns a number.

  • The findNode function searches for a node in a singly linked list based on a given callback function.

    Parameters

    • callbackFn: ((data, index, list) => boolean)

      A callback function that takes three parameters: data, index, and list. It returns a boolean value indicating whether the current node matches the desired criteria.

        • (data, index, list): boolean
        • Parameters

          Returns boolean

    Returns undefined | SinglyLinkedListNode<NodeVal>

    The function findNode returns a SinglyLinkedListNode<NodeVal> if a node satisfying the condition specified by the callbackFn is found in the linked list. If no such node is found, it returns undefined.

  • The function findNodeIndex searches for a node in a singly linked list that satisfies a given condition and returns its index and the node itself.

    Parameters

    • callbackFn: ((data, index, list) => boolean)

      The callbackFn parameter is a function that takes three arguments: data, index, and list. It is used to determine whether a node in the singly linked list matches a certain condition. The function should return a boolean value indicating whether the condition is met for the given node.

        • (data, index, list): boolean
        • Parameters

          Returns boolean

    Returns undefined | {
        index: number;
        node: SinglyLinkedListNode<NodeVal>;
    }

    The function findNodeIndex returns an object with two properties: node and index. The node property contains the node that matches the condition specified in the callbackFn function, and the index property contains the index of that node in the linked list. If no node matches the condition, the function returns undefined.

  • The forEach function iterates over a singly linked list and applies a callback function to each node, either in forward or reverse order.

    Parameters

    • callbackFn: ((data, index, list) => any)

      A callback function that will be called for each element in the linked list. It takes three parameters:

        • (data, index, list): any
        • Parameters

          Returns any

    • Optional reverse: boolean = false

      A boolean value indicating whether to iterate over the linked list in reverse order. If set to true, the iteration will start from the tail of the linked list and move towards the head. If set to false (default), the iteration will start from the head and move towards the tail.

    Returns void

  • The get function returns the value of a node at a given index in a data structure.

    Parameters

    • index: number

      The index parameter is a number that represents the position of the node in the data structure.

    Returns undefined | NodeVal

    The method is returning the value of the node at the specified index if the node exists, otherwise it returns undefined.

  • The insertAfter function inserts a new node with a given value after a specified reference node in a singly linked list.

    Parameters

    • referenceNode: SinglyLinkedListNode<NodeVal>

      The referenceNode parameter is the node after which the new node will be inserted.

    • val: NodeVal

      The value of the new node that will be inserted after the reference node.

    Returns SinglyLinkedList<NodeVal>

    The insertAfter method is returning the updated SinglyLinkedList object.

  • The insertAt function inserts a value at a specified index in a singly linked list.

    Parameters

    • index: number

      The index parameter is a number that represents the position at which the new node should be inserted in the linked list.

    • val: NodeVal

      The val parameter represents the value of the node that you want to insert into the linked list.

    Returns SinglyLinkedList<NodeVal>

    The method insertAt returns the updated SinglyLinkedList object.

  • The insertBefore function inserts a new node with a given value before a specified reference node in a singly linked list.

    Parameters

    • referenceNode: SinglyLinkedListNode<NodeVal>

      The referenceNode parameter is the node in the linked list before which the new node will be inserted.

    • val: NodeVal

      The value of the new node that will be inserted before the reference node.

    Returns SinglyLinkedList<NodeVal>

    The method is returning the updated SinglyLinkedList object.

  • The map function takes a callback function and applies it to each element in the linked list, returning a new linked list with the results.

    Parameters

    • callbackFn: ((data, index, list) => any)

      A callback function that will be applied to each element in the linked list. It takes three parameters:

        • (data, index, list): any
        • Parameters

          Returns any

    • Optional reverse: boolean = false

      The reverse parameter is a boolean value that determines whether the mapping should be done in reverse order or not. If reverse is set to true, the mapping will be done in reverse order. If reverse is set to false or not provided, the mapping will be

    Returns SinglyLinkedList<{} | NodeVal>

    The map function is returning a new SinglyLinkedList object.

  • The merge function merges two singly linked lists by updating the next and prev pointers, as well as the head, tail, and size properties.

    Parameters

    • list: SinglyLinkedList<NodeVal>

      The parameter "list" is a SinglyLinkedList object that contains nodes with data of type NodeVal.

    Returns void

  • The push function appends multiple NodeVal objects to a data structure and returns the new size of the data structure.

    Parameters

    • Rest ...args: NodeVal[]

      args is a rest parameter of type NodeVal[]. It allows the function to accept any number of arguments of type NodeVal.

    Returns number

    The size of the data structure after the nodes are appended.

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

    Parameters

    • callbackFn: ((accumulator, currentNode, index, list) => any)

      A callback function that will be called for each element in the linked list. It takes four parameters:

        • (accumulator, currentNode, index, list): any
        • Parameters

          • accumulator: any
          • currentNode: NodeVal
          • index: number
          • list: SinglyLinkedList<NodeVal>

          Returns any

    • Optional start: any

      The start parameter is an optional initial value for the accumulator. If provided, the reduce function will start accumulating from this value. If not provided, the reduce function will use the value of the first element in the linked list as the initial value.

    • Optional reverse: boolean = false

      A boolean value indicating whether to iterate over the linked list in reverse order. If set to true, the iteration will start from the tail of the linked list and move towards the head. If set to false (default), the iteration will start from the head and move towards the tail.

    Returns any

    The reduce method returns the accumulated value after applying the callback function to each element in the linked list.

  • The removeAt function removes a node at a specified index from a singly linked list.

    Parameters

    • index: number

      The index parameter is a number that represents the position of the node to be removed in the singly linked list.

    Returns undefined | SinglyLinkedListNode<NodeVal>

    The method removeAt returns a SinglyLinkedListNode<NodeVal> if the node at the specified index is found and removed successfully. If the node is not found, it returns undefined.

  • The function removes a node from either end of a singly linked list and returns its value.

    Parameters

    • node: null | SinglyLinkedListNode<NodeVal>

      The node parameter is a reference to a node in a singly linked list. It can be either a SinglyLinkedListNode object or null.

    Returns undefined | NodeVal

    The value of the removed node if the node is not null, otherwise undefined.

  • The slice function returns a new SinglyLinkedList containing a portion of the original list, starting from the specified index and ending at the optional end index.

    Parameters

    • start: number

      The start parameter is a number that represents the index at which to start slicing the linked list.

    • Optional end: number

      The end parameter is an optional number that specifies the index at which to end the slicing. If no value is provided for end, or if the provided value is less than the start index, the slicing will continue until the end of the list.

    Returns SinglyLinkedList<{} | NodeVal>

    a new SinglyLinkedList containing the sliced elements from the original list.

  • The sort function uses the quicksort algorithm to sort the elements of a singly linked list based on a provided comparison function.

    Parameters

    • compare: ((a, b) => boolean)
        • (a, b): boolean
        • Parameters

          • a: NodeVal
          • b: NodeVal

          Returns boolean

    Returns SinglyLinkedList<NodeVal>

    The sort method is returning the sorted SinglyLinkedList object.

  • The toString function takes an optional separator and returns a string representation of an array, with each element separated by the specified separator.

    Parameters

    • Optional separator: string = ' '

    Returns string

    The toString method is being returned as a string.

  • The from function in TypeScript creates a new SinglyLinkedList instance from an iterable object.

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable parameter is an object that can be iterated over, such as an array or a string. It contains a collection of elements of type T.

    Returns SinglyLinkedList<T>

    The method is returning a new instance of the SinglyLinkedList class.

Generated using TypeDoc