Given a singly linked list, find if the linked list is circular or not. A linked list is called circular if it is not NULL-terminated and all nodes are connected in the form of a cycle. Below is an example of a circular linked list.
An empty linked list is considered as circular.
Note that this problem is different from cycle detection problem, here all nodes have to be part of cycle.
The idea is to store head of the linked list and traverse it. If we reach NULL, linked list is not circular. If reach head again, linked list is circular.
This article is contributed by Shivam Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Convert singly linked list into circular linked list
- Split a Circular Linked List into two halves
- Sorted insert for circular linked list
- Circular Singly Linked List | Insertion
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Doubly Circular Linked List | Set 2 (Deletion)
- Circular Linked List | Set 1 (Introduction and Applications)
- Circular Linked List | Set 2 (Traversal)
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Count nodes in Circular linked list
- Josephus Circle using circular linked list
- Exchange first and last nodes in Circular Linked List
- Reverse a circular linked list
- Insertion at Specific Position in a Circular Doubly Linked List
- Convert an Array to a Circular Doubly Linked List
- Reverse a doubly circular linked list
- Search an Element in Doubly Circular Linked List
- Delete every Kth node from circular linked list
- Sum of the nodes of a Circular Linked List