LinkedList

Intro

LinkedList<T> is a doubly linked list where each node points to previous and next nodes. It is useful when you already keep node references and need frequent O(1) inserts/removes around those nodes.

Unlike array-backed collections, linked lists do not store elements contiguously:

Structure

graph LR
    H[head] --> N1[node a]
    N1 <--> N2[node b]
    N2 <--> N3[node c]
    N3 --> T[tail]

Example

var list = new LinkedList<string>();
var a = list.AddLast("A");
list.AddLast("C");

list.AddAfter(a, "B");
list.Remove("C");

Pitfalls

Tradeoffs

Questions


Whats next