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)
- 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 a doubly linked list that are smaller than a given value
- Delete all Prime Nodes from a Doubly Linked List
- 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 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
- 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 alternate nodes of a Linked List
- Delete all the even nodes of a Circular 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.