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
- Sum of the nodes of a Circular Linked List
- Delete all the even nodes of a Circular Linked List
- Count nodes in Circular linked list
- Exchange first and last nodes in Circular Linked List
- Delete all odd or even positioned nodes from Circular Linked List
- Delete all Prime Nodes from a Circular Singly Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Delete N nodes after M nodes of a linked list
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Linked List Sum of Nodes Between 0s
- Sum and Product of all the nodes which are less than K in the linked list
- Linked List Product of Nodes Between 0s
- Sum of all odd frequency nodes of the Linked List
- Find the sum of last n nodes of the given Linked List
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.
Improved By : Rajput-Ji