Skip to main content

How are nodes connected to each other in a list?

Nodes in a linked list are connected to each other by references (pointers) - special fields that store the address of the next (or previous) node in memory.

That is, each node knows where to go next, forming a chain.


1. Singly linked list

Each node contains:

  • data,
  • a reference to the next node (next).

Example:

javascript
head → [10 | *][20 | *][30 | None]
  • head points to the first node;
  • the next of the first node points to the second;
  • the next of the second points to the third;
  • the next of the last one (tail) = None → end of the list.

The point: movement is possible only forward.


2. Doubly linked list

Each node stores two references:

  • prev - to the previous node,
  • next - to the next node.

Example:

javascript
None[10 | * | *][20 | * | *][30 | * | None]
  • head.prev = None
  • tail.next = None
  • Each internal node knows its neighbors on both sides.

The point: you can move forward and backward.


3. Circular list

The last node does not point to None, but closes back onto the first (head):

javascript
[A | *][B | *][C | *] ↑__________________↓
  • tail.next = head
  • Sometimes also head.prev = tail (in a circular doubly linked list).

The point: movement happens in a circle - the list has no end.


4. Visually (an analogy)

Imagine a train:

  • each car (node) knows which car it is coupled to next,
  • sometimes also which one is behind it.
  • If the coupling closes into a circle, it is a circular list.

Summary:

Nodes are connected to each other through references (pointers) that carry the address of the next (and sometimes the previous) element. These connections form a "chain" that lets you traverse the list sequentially.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.