Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LinkedList<T>

Linked list

In computer science, a linked list is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.

Linked list source: www.thecodingdelight.com

Complexity

Algorithm Average Worst case
Access O(n) O(n)
Search O(n) O(n)
Insert O(1) O(1)
Delete O(1) O(1)
- - -
Space O(n) O(n)

Reference

import { LinkedList } from '@pencroff/ts-algorithms/dist/structure/linked';
const list = new LinkedList([1, 2, 3])

LinkedList implements generic doubly linked list

Type parameters

  • T

Hierarchy

  • LinkedList

Implements

  • Iterable<T>

Index

Constructors

constructor

Properties

Private _first

_first: LinkedListNode<T>

Private _last

_last: LinkedListNode<T>

Private _len

_len: number

Private comparator

comparator: ComparatorFn<T>

Accessors

first

last

length

  • get length(): number

Methods

__@iterator

  • __@iterator(): Iterator<T>

backward

  • backward(): Iterable<T>

clear

  • clear(): void

find

findLast

has

  • has(value: T): boolean

insertAfter

insertBefore

insertFirst

insertLast

remove

removeFirst

  • removeFirst(): boolean

removeLast

  • removeLast(): boolean

reverse

toArray

  • toArray(): T[]

Private toNode