Class SinglyLinkedList<T>

Type Parameters

  • T

Hierarchy

  • SinglyLinkedList

Constructors

Properties

_head: null | SinglyLinkedListNode<T>
_length: number
_tail: null | SinglyLinkedListNode<T>

Accessors

Methods

  • The function counts the number of occurrences of a given value in a linked list.

    Parameters

    • value: T

      The value parameter is the value that you want to count the occurrences of in the linked list.

    Returns number

    The count of occurrences of the given value in the linked list.

  • The delete function removes a specified value from a linked list and returns true if the value was found and removed, otherwise it returns false.

    Parameters

    • value: T

      The value parameter represents the value of the node that needs to be deleted from the linked list.

    Returns boolean

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

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

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

  • 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 function finds a node in a singly linked list by its value and returns the node if found, otherwise returns null.

    Parameters

    • value: T

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

    Returns null | SinglyLinkedListNode<T>

    a SinglyLinkedListNode<T> if a node with the specified value is found in the linked list. If no node with the specified value is found, the function returns null.

  • The function getAt returns the value at a specified index in a 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 element we want to retrieve from the list.

    Returns null | T

    The method getAt(index: number): T | null returns the value at the specified index in the linked list, or null if the index is out of bounds.

  • The function getNodeAt returns the node at a given index in a singly linked list.

    Parameters

    • index: number

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

    Returns null | SinglyLinkedListNode<T>

    The method getNodeAt(index: number) returns a SinglyLinkedListNode<T> object if the node at the specified index exists, or null if the index is out of bounds.

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

    Parameters

    • value: T

      The value parameter is the value that you want to find the index of in the linked list.

    Returns number

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

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

    Parameters

    • index: number

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

    • val: T

      The val parameter represents the value that you want to insert into the 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.

  • The function inserts a new value after an existing value in a singly linked list.

    Parameters

    • existingValue: T

      The existing value is the value of the node after which we want to insert the new value.

    • newValue: T

      The newValue parameter represents the value that you want to insert into the linked list after the node with the existingValue.

    Returns boolean

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

  • The insertBefore function inserts a new value before an existing value in a singly linked list.

    Parameters

    • existingValue: T

      The existing value is the value that already exists in the linked list and before which we want to insert a new value.

    • newValue: T

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

    Returns boolean

    The insertBefore function returns a boolean value. It returns true if the newValue is successfully inserted before the first occurrence of existingValue in the linked list. It returns false if the existingValue is not found in the linked list.

  • The function checks if the length of a data structure is equal to zero and returns a boolean value indicating whether it is empty or not.

    Returns boolean

    A boolean value indicating whether the length of the object is equal to 0.

  • The pop() function removes and returns the value of the last element in a linked list, updating the head and tail pointers accordingly.

    Returns null | T

    The method pop() returns the value of the node that is being removed from the end of the linked list. If the linked list is empty, it returns null.

  • The push function adds a new node with the given data to the end of a singly linked list.

    Parameters

    • data: T

      The "data" parameter represents the value that you want to add to the linked list. It can be of any type (T) as specified in the generic type declaration of the class or function.

    Returns void

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

    Parameters

    • val: T

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

    Returns void

Generated using TypeDoc