Circular Linked List

DSA · Linked Lists

Theory

In a circular linked list the last node points back to the first instead of to None, so traversal can continue around the loop forever. A pointer to any node gives access to the whole list. You must stop traversal when you return to the starting node to avoid an infinite loop.

Why we use it

It naturally models things that repeat in a cycle.

When to use it

Use it for round-robin scheduling, rotating turns in a game, and circular buffers.

How it works

  1. Start at head
  2. Visit node
  3. current = current.next
  4. current == head? Yes: Full circle: stop. No: Continue visiting.
  5. Done

Syntax

tail.next = head

Traverse:
cur = head
do:
    visit(cur); cur = cur.next
while cur is not head

Example

class Node:
    def __init__(self, val):
        self.val = val
        self.next = None

players = [Node(n) for n in ["Asha", "Ravi", "Neha"]]
for i in range(len(players)):
    players[i].next = players[(i + 1) % len(players)]

turn = players[0]
for round_no in range(1, 7):
    print("Turn", round_no, ":", turn.val)
    turn = turn.next

Key points

DSA topics

Introduction to DSA

Arrays and Searching

Sorting Algorithms

Linked Lists

Stacks and Queues

Hashing

Trees

Heaps

Graphs

Algorithm Techniques

Classic Algorithms

Dynamic Programming

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Data Structures & Algorithms

The complete DSA roadmap: theory, why and when to use every structure and algorithm, Big O complexity, and Python code you can run right here in the browser.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice DSA Online 251 problems across 13 patterns, with hidden tests and step-by-step optimal solutions. Start practising →
Section {{ sec.num }}

{{ sec.label }}

DSA  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ current.why }}

When to use it

{{ current.when }}

Flowchart — how {{ current.name }} works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Step-by-step visualisation
{{ cell.v }}
{{ cell.i }} {{ cell.tag }}
Step {{ vizStepLabel }}: {{ vizNote }}
■ comparing ■ swapping / moving ■ done / found ■ out of range
Complexity & Pseudocode
{{ current.syntax }}
Example Code
{{ current.example }}
▶ Try It Live — runs real Python 3 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic