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
- Exchange first and last nodes in Circular Linked List
- Delete all the even nodes of a Circular Linked List
- Count 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
- Find sum of even and odd nodes in a linked list
- Sum of all distinct nodes in a linked list
- Sum of the nodes of a Singly Linked List
- Sum of all odd frequency nodes of the 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 email@example.com. 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