API Docs for:
Show:

LinkedList Class

Singly-linked list.

Constructor

LinkedList

()

Methods

clear

()

Resets the list, removing all nodes.

get

(
  • index
)

Retrieves a value stored in a node under the given index. If the index is out of bounds, an error will be thrown.

Parameters:

  • index Number

Returns:

Value of the node under the given index.

getFirst

() LinkedListNode | Null

Returns:

LinkedListNode | Null: First node on the list. If the list is empty, this value will be null.

getLength

() Number

Returns:

Number: Length of the list.

indexOf

(
  • value
)
Number

Returns the index of the first node holding the provided value.

Parameters:

  • value Object

Returns:

Number: Index of the first node holding the given value. If no node holds the value, the function will return -1.

insert

(
  • index
  • value
)

Inserts a given value under the given index, shifting following values by one. Throws an error if the index is out of bounds.

Parameters:

  • index Number

    Index under which the value should be placed.

  • value Object

    The value to be inserted

merge

(
  • list
  • [index]
)

Merges the list with another. Does not copy.

Parameters:

  • list LinkedList

    List to be merged.

  • [index] Number optional

    Index under which the list being merged should be placed. If no index is provided, the list is appened at the end.

removeIf

(
  • condition
  • [removeAll]
)
Boolean

Removes the first or all nodes for which the provided function returns true.

Parameters:

  • condition Function

    Function used to evaluate whether a node should be removed. This function should accept a node value and return Boolean.

  • [removeAll] Boolean optional

    If this parameter is true, all nodes for which the condition function will return true will be removed. If it's false, only the first matching node will be removed.

Returns:

Boolean: True if a node was removed, otherwise false

removeIndex

(
  • index
)

Removes the node under the index from the list. If the provided index is out of bounds or the list is empty, an error with be thrown.

Parameters:

  • index Number

    Index of the node to be removed.

Returns:

The value stored in the removed node.

removeValue

(
  • value
  • [removeAll]
)
Boolean

Removes the first or all nodes holding the given value from the list.

Parameters:

  • value Number

    Value to be removed.

  • [removeAll] Boolean optional

    If this parameter is true, all values matching the first parameter will be removed. If it's false, only the first match will be removed.

Returns:

Boolean: True if a node was removed, otherwise false

reverse

()

Reverses the list.

subList

(
  • beginIndex
  • [count]
)
LinkedList

Creates a reduced in size copy of the list. If the beginning index is out of bounds, an error will be thrown.

Parameters:

  • beginIndex Number

    Index from which the copy process should start.

  • [count] Number optional

    Number of nodes to be copied into the new list. If the count is out of bounds or not set, then the created list will contain all elements from the beginning index to the end of the list being copied. This value can't be negative.

Returns:

LinkedList: The newly created subset.

toArray

() Array

Returns:

Array: An array holding all values stored in the list.