Given a singly linked list, we have to convert it into circular linked list. For example, we have been given a singly linked list with four nodes and we want to convert this singly linked list into circular linked list.
The above singly linked list is converted into circular linked list.
Approach: The idea is to traverse the singly linked list and check if the node is the last node or not. If the node is the last node i.e pointing to NULL then make it point to the starting node i.e head node. Below is the implementation of this approach.
Display list: 17 22 13 14 15
This article is contributed by Dharmendra kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Convert Singly Linked List to XOR Linked List
- Circular Singly Linked List | Insertion
- Delete all Prime Nodes from a Circular Singly Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Find minimum and maximum elements in singly Circular Linked List
- Convert a Singly Linked List to an array
- Difference between Singly linked list and Doubly linked list
- Convert an Array to a Circular Doubly Linked List
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Check if a linked list is Circular Linked List
- Circular Queue | Set 2 (Circular Linked List Implementation)
- QuickSort on Singly Linked List
- Sum of the nodes of a Singly Linked List
- Alternate Odd and Even Nodes in a Singly Linked List
- Implement a stack using singly linked list
- Product of the nodes of a Singly Linked List
- Binary Search on Singly Linked List