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 email@example.com. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Convert Singly Linked List to XOR Linked List
- Circular Singly Linked List | Insertion
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Delete all Prime Nodes from a Circular Singly Linked List
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Find minimum and maximum elements in singly Circular Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Convert a Singly Linked List to an array
- Convert an Array to a Circular Doubly Linked List
- Difference between Singly linked list and 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