← Back to Blog

Doubly Linked List Explained - Two Pointers, Both Directions

Doubly Linked ListLinked ListData StructurePointerAlgoNote

What Is a Doubly Linked List?

A doubly linked list is a data structure where each node holds data plus two pointers: prev (to the previous node) and next (to the next node).

While a singly linked list can only move forward through a single next pointer, a doubly linked list can traverse freely in both directions. The previous/next track buttons of a music player and the back/forward buttons of a browser are all applications of this structure.


How Does It Differ from a Singly Linked List?

AspectSinglyDoubly
Pointersnext onlyprev + next
Traversalforward onlyboth ways
Node deletionmust find the previous nodeO(1) with a node reference
Memorylessextra for prev

There are two key differences.

  • Reverse traversal: You can scan backward from the tail via prev — impossible in a singly linked list.
  • O(1) deletion: Given a reference to the node, link its neighbors directly via prev/next and delete without searching.

The Core Approach

There is one principle you must never forget when working with a doubly linked list: when relinking, always update both pointers as a pair.

  • Add at front/back: Link the new node's prev/next to the end node, and point the end node's pointer back to the new node.
  • Insert in the middle: Update four pointers in total — the previous node's next, the following node's prev, and the new node's prev/next.
  • Delete: Use node.prev.next = node.next and node.next.prev = node.prev to link the neighbors and bypass the node.

If you update only one side, the opposite-direction link breaks and traversal falls apart — so "both sides as a pair" is the most important instinct to build.


See It in Action on AlgoNote

Watch how the prev/next bidirectional arrows update on every insert and delete, and how a backward search starting from the tail works — all step by step on AlgoNote.

Try the Doubly Linked List Visualization →

Doubly Linked List Explained - Two Pointers, Both Directions - AlgoNote | 알고노트(AlgoNote)