LinkedList

DataStructure. LinkedList

Linked lists are used to implement other data structures because of its ability to efficiently add items to the start, middle, and end.

A linked list is similar to a graph. You have nodes that point to other nodes. They look sorta like this:
1 -> 2 -> 3 -> 4 -> 5
Visualizing them as a JSON-like structure looks like this:
{
 value: 1,
 next: {
  value: 2,
  next: {
   value: 3,
   next: {...}
  }
 }
}

Constructor

new LinkedList()

A linked list has a single node that starts off the entire chain. This is known as the "head" of the linked list Note that we to store the length separately because the "memory" doesn't have a length that can be read.
Source:

Methods

add(value, position)

Add nodes to the specified position
Parameters:
Name Type Description
value * Value that should be added to the list
position Number Postion where the value should be added
Source:

get(position) → {null|*|Object}

Retrieve a value in a given position. This works differently than normal lists as we can't just jump to the correct position. Instead we need to move through the individual nodes.
Parameters:
Name Type Description
position Number Position of element in List
Source:
Returns:
Type
null | * | Object

remove(position)

Look up a node by its position and splice it out of the chain.
Parameters:
Name Type Description
position Number Position of node that should be spliced out
Source: