Given a linked list, the problem is to delete all the nodes from the list that are greater than the specified value x.
Input : list: 7->3->4->8->5->1 x = 6 Output : 3->4->5->1 Input : list: 1->8->7->3->7->10 x = 7 Output : 1->7->3->7
Approach: This is mainly a variation of the post which deletes first occurrence of a given key.
We need to first check for all occurrences at head node which are greater than ‘x’, delete them and change the head node appropriately. Then we need to check for all occurrences inside a loop and delete them one by one.
Original List: 7 3 4 8 5 1 Modified List: 3 4 5 1
Time Complexity: O(n).
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Delete all the nodes from the doubly linked list that are greater than a given value
- Delete linked list nodes which have a greater value on left side
- Delete nodes which have a greater value on right side
- Delete nodes which have a greater value on right side using recursion
- Delete N nodes after M nodes of a linked list
- Delete all the nodes from the list which are less than K
- Delete all the even nodes of a Circular Linked List
- Delete all odd nodes of a Circular Linked List
- Delete all the even nodes from a Doubly Linked List
- Delete all the nodes from the list which are divisible by any given number K
- Delete continuous nodes with sum K from a given linked list
- Delete alternate nodes of a Linked List
- Delete all the nodes from a doubly linked list that are smaller than a given value
- Program to delete all even nodes from a Singly 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 all Non-Prime Nodes from a Singly Linked List
- Delete all odd or even positioned nodes from Circular Linked List
- Delete all Prime Nodes from a Singly Linked List
- Delete all Prime Nodes from a Circular Singly 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 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.
Improved By : Monika Jalota