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

LinkedList class — API reference covering node operations, AddBefore/AddAfter, and enumeration.
  • Selecting a collection class — Microsoft decision guide; explains when linked list is appropriate vs array-backed collections.
  • Performance tips for collections — overview of .NET collection types with complexity and memory characteristics.
  • Exploring C# LinkedLists via LRU Caches — practitioner example of a real use case (LRU cache) where O(1) node-local edits justify linked list overhead.

  • Whats next

    Parent
    02 Computer Science

    Pages