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
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 into circular linked list
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Check if a linked list is Circular Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Merge a linked list into another linked list at alternate positions
- Adding two polynomials using Circular Linked List
- Create new linked list from two given linked list with greater element at each node
- Sorted insert for circular linked list
- Circular Singly Linked List | Insertion
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Doubly Circular Linked List | Set 2 (Deletion)
- Circular Linked List | Set 1 (Introduction and Applications)
- Circular Linked List | Set 2 (Traversal)
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Count nodes in Circular linked list
- Josephus Circle using circular linked list
- Exchange first and last nodes in Circular Linked List
- Reverse a circular linked list
- Insertion at Specific Position in a Circular Doubly Linked List
- Convert an Array to a Circular Doubly Linked List