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
- 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
- Recursive approach for alternating split of Linked List
- Circular Linked List | Set 2 (Traversal)
- Reverse a circular linked list
- Deletion from a Circular Linked List
- Sum of the nodes of a Circular Linked List
- Delete every Kth node from circular linked list
- Delete all the even nodes of a Circular Linked List
- Delete all odd nodes of a Circular Linked List
- Reverse a doubly circular linked list
- Doubly Circular Linked List | Set 2 (Deletion)
- Circular Linked List | Set 1 (Introduction and Applications)