This repository contains an implementation of a singly linked list in JavaScript. The linked list supports various operations such as appending, prepending, inserting, removing, and searching nodes.
The files use ES Module syntax, therefore uses the .mjs
file extension.
append(value)
: Adds a new node containingvalue
to the end of the list.prepend(value)
: Adds a new node containingvalue
to the start of the list.getSize()
: Returns the total number of nodes in the list.getHead()
: Returns the first node in the list.getTail()
: Returns the last node in the list.at(index)
: Returns the node at the givenindex
.pop()
: Removes the last element from the list.contains(value)
: Returnstrue
if the list contains a node with the givenvalue
, else returnsfalse
.find(value)
: Returns the index of the node containingvalue
, ornull
if not found.insertAt(value, index)
: Inserts a new node with the providedvalue
at the givenindex
.removeAt(index)
: Removes the node at the givenindex
.toString()
: Prints the linked list in the format( value ) -> ( value ) -> ... -> null
.
constructor(value = null)
: Creates a new node with the specifiedvalue
. ThenextNode
property is initialized tonull
.