Skip to content

Circular Linked List Visualizer

The last node links back to the first: see the circle in memory and how each operation keeps it closed.

Links
View
Nodes: 0 Node size: 16 bytes Pointer steps: 0
  • Current node
  • New or found
  • Being deleted
  • Free memory

Each box is a node at its own memory address. The pointer field holds the address of the next node (and the previous one); the arrows show where it points.

Step 1 of 1

// tail.next is always the headinsertHead(v):  node = new Node(v)  if tail = null: node.next = node; tail = node; return  node.next = tail.next   // the old head  tail.next = node  (head is now node)insertTail(v):  node = new Node(v)   // empty list: same as insertHead  node.next = tail.next  tail.next = node  tail = nodeinsertAt(i, v):  if i = 0: insertHead(v); return  cur = tail.next; repeat i − 1 times: cur = cur.next  node = new Node(v)  node.next = cur.next  cur.next = node; if cur = tail: tail = nodedelete(v):  cur = tail.next  repeat n times: if cur.value = v: stop; cur = cur.next  if not found: return  prev.next = cur.next; fix tail if cur was tail  free cursearch(v):  cur = tail.next; i = 0  do: if cur.value = v: return i      cur = cur.next; i = i + 1  while cur ≠ tail.next; return −1reverse():  prev = tail; cur = tail.next  repeat n times    next = cur.next    cur.next = prev    prev = cur; cur = next  tail = old head (tail.next is the new head)
Circular singly linked list operations
OperationTime
Access by indexO(n)
SearchO(n)
Insert at headO(1)
Insert at tailO(1) with a tail pointer
Insert after a known nodeO(1)
Delete a known nodeO(n) to find the previous node
Extra memory per node1 pointer

A circular linked list has no NULL at the end: the last node points back to the first, so the nodes form a ring. This visualizer shows the ring in memory with real addresses and arrows, including the pointer from the tail back to the head. A switch turns it from a circular singly linked list into a circular doubly linked list, where the head’s prev pointer also points to the tail.

Insert at the head, tail or an index, delete, search and reverse, and see how each operation keeps the circle closed. Because the tail points to the head, keeping just a tail pointer gives O(1) access to both ends, a trick used by many real implementations.

How to use the Circular Linked List Visualizer tool

  1. Choose Singly or Doubly links.
  2. Type a value (and an index) and pick an operation.
  3. Watch the arrow from the last node back to the first, and the red arrow for the pointer being changed.
  4. Step back and forth, or switch to List order to see the ring as a row that wraps around.

Why use ToolOrca Circular Linked List Visualizer

  • Circular singly and circular doubly modes
  • Tail-to-head link drawn in memory
  • Insert at head, tail or index, delete, search, reverse
  • Search stops after one full lap
  • Pseudocode for each mode, with the active line highlighted
  • Code in C++, Java, Python and JavaScript

How a circular linked list works

In a circular singly linked list the last node’s next pointer holds the address of the first node. If you keep a pointer to the tail, the head is just tail.next, so both ends are one step away: inserting at the head or the tail is O(1). In a circular doubly linked list the head’s prev pointer also points to the tail.

Since there is no NULL, loops must stop in a different way: you stop when you get back to the node you started from. Forgetting this is the classic bug with circular lists, an endless loop.

Keeping the circle closed

Every operation must keep the ring intact. Inserting at the head means node.next = head, then tail.next = node. Inserting at the tail is the same plus moving tail to the new node. Deleting the only node empties the list; deleting the head or tail means updating the pointer that referred to it. A single node points to itself.

Where circular lists are used

Circular lists suit anything that cycles: round-robin CPU scheduling, taking turns in multiplayer games, the Josephus problem, repeating playlists and ring buffers. Search, access by index and deleting by value are still O(n), as in any linked list.

Every visualizer on this site runs in your browser with the same controls: Play, Pause, Step forward, Step back and a speed slider. You can also drag the position slider to jump to any step, or focus the drawing and use the Space bar and arrow keys.

Frequently asked questions

What is a circular linked list?

A linked list where the last node points back to the first instead of to NULL, so you can keep walking around the list forever.

How do you know when you have visited every node?

Remember the node you started from (usually the head) and stop when the next pointer brings you back to it.

Why keep a tail pointer instead of a head pointer?

Because tail.next is the head, a single tail pointer gives O(1) access to both ends. With only a head pointer, reaching the tail would take O(n).

What is the Josephus problem?

People stand in a circle and every k-th person is removed until one remains. A circular linked list models it directly: walk k steps, delete a node, repeat.