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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Sum of the nodes of a Circular Linked List
- Delete all odd nodes of a Circular Linked List
- Count nodes in Circular linked list
- Exchange first and last nodes in Circular Linked List
- Delete all the even nodes of a Circular Linked List
- Sum and Product of nodes with value as even digit sum 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
- 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
- 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
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.