Topic 3
Circular Linked List
Circular vs Singly โ The Key Difference
The last node points back to head instead of NULL.
Critical code differences:
โข Empty single node: head->next == head (not NULL)
โข Traversal: while(temp->next != head)
โข Display: Uses do-while loop
โข Insert at beginning: Must also update last node's next
Circular Linked List
Singly vs Circular โ Critical Differences
| Aspect | Singly LL | Circular LL |
|---|---|---|
| Last node points to | NULL | head |
| Traversal condition | temp != NULL | temp->next != head |
| Display loop | while loop | do-while loop |
| Single node check | head->next == NULL | head->next == head |
| Empty list, first add | newNode->next = NULL | newNode->next = newNode |
| Insert at beginning | Just update head | Update head + last->next |
| Delete from beginning | Move head forward | Move head + update last->next |
complete-circular-linked-list