Original Linked List
Result Linked List 1
Result Linked List 2
If there are odd number of nodes, then first list should contain one extra.
Thanks to Geek4u for suggesting the algorithm.
1) Store the mid and last pointers of the circular linked list using tortoise and hare algorithm.
2) Make the second half circular.
3) Make the first half circular.
4) Set head (or start) pointers of the two linked lists.
In the below implementation, if there are odd nodes in the given circular linked list then the first result list has 1 more node than the second result list.
Original Circular Linked List 11 2 56 12 First Circular Linked List 11 2 Second Circular Linked List 56 12
Time Complexity: O(n)
Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem
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.
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Convert singly linked list into circular linked list
- Check if a linked list is Circular Linked List
- Reverse a circular linked list
- Circular Linked List | Set 2 (Traversal)
- Deletion from a Circular Linked List
- Sum of the nodes of a Circular Linked List
- Alternating split of a given Singly Linked List | Set 1
- Circular Linked List | Set 1 (Introduction and Applications)
- Exchange first and last nodes in Circular Linked List
- Josephus Circle using circular linked list
- Doubly Circular Linked List | Set 2 (Deletion)
- Circular Singly Linked List | Insertion
- Count nodes in Circular linked list
- Reverse a doubly circular linked list
- Sorted insert for circular linked list
- Deletion at different positions in a Circular Linked List
- Delete all the even nodes of a Circular Linked List
- Delete all odd nodes of a Circular Linked List
- Delete every Kth node from circular linked list