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.
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.
- Convert Singly Linked List to XOR Linked List
- Circular Singly Linked List | Insertion
- Delete all Prime Nodes from a Circular Singly Linked List
- Find minimum and maximum elements in singly Circular 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
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Difference between Singly linked list and Doubly linked list
- Convert a Singly Linked List to an array
- Split a Circular Linked List into two halves
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Check if a linked list is Circular Linked List
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Convert an Array to a Circular Doubly Linked List
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Alternating split of a given Singly Linked List | Set 1
- Reverse alternate K nodes in a Singly Linked List
- QuickSort on Singly Linked List