Data Structures•Medium
Circular Linked List
Circular Linked List
In a Circular Linked List, the tail node's next pointer does not point to NULL. Instead it loops back to the head, creating a circular structure.
Structure
HEAD -> [10] -> [20] -> [30] -> [40]
|________________________|
Types
- Singly Circular — each node has only
next; tail->next = head - Doubly Circular — each node has
prevandnext; tail->next = head AND head->prev = tail
Key Properties
- No NULL — traversal never reaches null; you stop when you loop back to head
- Any node can be head — useful for round-robin scheduling
- Infinite loop risk — must track the starting node when traversing
Use Cases
- CPU scheduling (Round Robin)
- Multiplayer turn-based games
- Music playlist loop
- Browser tab cycling
Detecting end of traversal
Instead of while (temp != NULL), use a do-while:
do {
// process temp->data
temp = temp->next;
} while (temp != head);