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 Prime Nodes from a Doubly Linked List
- Cracking Technical Interviews; Freshers
- Sum of all nodes in a doubly linked list divisible by a given number K
- Which language should you learn first if you want to make an app?
- Delete linked list nodes which have a greater value on left side
- Reverse a doubly circular linked list
- Design a data structure for LRU Cache
- Delete all Prime Nodes from a Singly Linked List
- Delete linked list nodes which have a Lesser Value on Left Side
- Delete all nodes from the doubly linked list which are divisible by K
- Check if two Linked Lists are permutations of each other
- Print Doubly Linked list in Reverse Order
- Sort Linked List containing values from 1 to N
- Find the Second Largest Element in a Linked List
- Sort a Linked List in wave form
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.