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 Singly Linked List | Insertion
- Check if a linked list is Circular Linked List
- Circular Linked List | Set 2 (Traversal)
- Circular Linked List | Set 1 (Introduction and Applications)
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Detect and Remove Loop in a Linked List
- Sorted insert for circular linked list
- Delete a node in a Doubly Linked List
- Move last element to front of a given Linked List
- Practice questions for Linked List and Recursion
- Reverse a Doubly Linked List
- The Great Tree-List Recursion Problem.
- Function to check if a singly linked list is palindrome
- Reverse a linked list
- Find the middle of a given linked list in C and Java