Given a doubly linked list containing N nodes and a number X, the task is to delete all the nodes from the list that are greater than the given value X.
Input: 10 8 4 11 9, X = 9
Output: 8 4 9
Input: 4 4 2 1 3 5, X = 2
Output: 2 1
Approach: Traverse the nodes of the doubly linked list one by one and get the pointer of the nodes having data value greater than x. Delete these nodes by following the approach used in this post.
Original List: 10 8 4 11 9 Modified List: 8 4 9
Time Complexity: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Delete all the nodes from a doubly linked list that are smaller than a given value
- Delete all the even nodes from a Doubly Linked List
- Delete all Prime Nodes from a Doubly Linked List
- Delete all nodes from the doubly linked list which are divisible by K
- Delete linked list nodes which have a greater value on left side
- Delete all the nodes from the list that are greater than x
- Delete all occurrences of a given key in a doubly linked list
- Sum of all nodes in a doubly linked list divisible by a given number K
- Product of all nodes in a doubly linked list divisible by a given number K
- Delete a Doubly Linked List node at a given position
- Delete N nodes after M nodes of a linked list
- Delete linked list nodes which have a Lesser Value on Left Side
- Remove all the Even Digit Sum Nodes from a Doubly Linked List
- Product of all prime nodes in a Doubly Linked List
- Remove all nodes from a Doubly Linked List containing Fibonacci numbers
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Delete a node in a Doubly Linked List
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Difference between Singly linked list and Doubly 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.