Given a doubly linked list containing N nodes and a number K, the task is to delete all the nodes from the list that are smaller than the given value K.
Input: 15 <=> 16 <=> 10 <=> 9 <=> 6 <=> 7 <=> 17 K = 10 Output: 15 <=> 16 <=> 10 <=> 17 Input: 5 <=> 3 <=> 6 <=> 8 <=> 4 <=> 1 <=> 2 <=> 9 K = 4 Output: 5 <=> 6 <=> 8 <=> 4 <=> 9
Approach: Traverse the nodes of the doubly linked list one by one and get the pointer of the nodes having data value smaller than K. Refer to the article on Deleting a node from Doubly Linked List to delete a node.
Below is the implementation of the above approach:
Original List: 15 16 10 9 6 7 17 Modified List: 15 16 10 17
Time Complexity: O(N), where N is the total number of Nodes.
- Delete all the even nodes from a Doubly Linked List
- Delete all nodes from the doubly linked list which are divisible by K
- Delete all the nodes from the doubly linked list that are greater than a given value
- Delete all Prime Nodes from a Doubly Linked List
- Delete a node in a Doubly Linked List
- Delete all occurrences of a given key in a doubly linked list
- Delete a Doubly Linked List node at a given position
- Sum of smaller elements of nodes in a linked list
- Delete N nodes after M nodes of a linked list
- Rotate Doubly linked list by N nodes
- Sum of all nodes in a doubly linked list divisible by a given number K
- Product of all prime nodes in a Doubly Linked List
- Delete all the even nodes of a Circular Linked List
- Delete alternate nodes of a Linked List
- Product of all nodes in a doubly linked list divisible by a given number K
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.