Given a circular linked list with N nodes and an integer K where 0 < K < N, the task is to split the first K nodes into a new list and at the same time preserving the rest of the nodes in the original circular linked list.
Input: 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8, K = 3
2 3 4 5 6 7 8
The new lists are:
2 3 4
5 6 7 8
Input: 2 -> 4 -> 6 -> 8- > 10 -> 12, N = 4
2 4 6 8 10 12
The new lists are:
2 4 6 8
- Traverse an iterator until the required node i.e. the Kth node.
- Point the node just previous to the Kth node to the head of the original list.
- Point the last node of the original list to the Kth node.
Below is the implementation of the above approach:
Original list: 2 4 6 8 10 12 The new lists are: 2 4 6 8 10 12
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)
- Create new linked list from two given linked list with greater element at each node
- Check if a linked list is Circular Linked List
- Split a Circular Linked List into two halves
- Merge a linked list into another linked list at alternate positions
- Count nodes in Circular linked list
- Exchange first and last nodes in Circular Linked List
- Sum of the nodes of a Circular Linked List
- Delete all the even nodes of a Circular Linked List
- Delete all Prime Nodes from a Circular Singly Linked List
- Delete all odd or even positioned nodes from Circular Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Delete all odd nodes of a Circular Linked List
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Sum and Product of nodes with value as even digit sum in Circular Linked List
- Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List
- Check if a string can be split into substrings starting with N followed by N characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.