ListNode

ListNode

Represents a node in a singly linked list.

Constructor

new ListNode(valopt, nextopt)

Description:
  • Creates a new ListNode.
Source:
Parameters:
Name Type Attributes Default Description
val * <optional>
0 The value of the node.
next ListNode <optional>
null The next node in the list.

Classes

ListNode

Methods

toArr() → {Array}

Description:
  • Converts the linked list to an array. Detects cycles and throws an error if one is found.
Source:
Throws:
If a cyclic reference is detected.
Type
Error
Returns:
An array containing the values of the list nodes.
Type
Array

(static) fromArr(iter) → {ListNode|null}

Description:
  • Creates a linked list from an iterable.
Source:
Parameters:
Name Type Description
iter Iterable The iterable to create the list from.
Returns:
The head of the created linked list, or null if empty.
Type
ListNode | null