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
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
- 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
- Alternating split of a given Singly Linked List | Set 1
- 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
- Recursive approach for alternating split of Linked List
- Reverse a doubly circular linked list
- Josephus Circle using circular linked list
- Exchange first and last nodes in Circular Linked List
- Delete every Kth node from circular linked list
- Deletion at different positions in a Circular Linked List
- Count nodes in Circular linked list