Given a doubly linked list containing N nodes, the task is to delete all the even nodes from the list.
Input: Initial List = 15 <=> 16 <=> 6 <=> 7 <=> 17
Output: Final List = 15 <=> 7 <=> 17
Input: Initial List = 5 <=> 3 <=> 6 <=> 8 <=> 4 <=> 1 <=> 2 <=> 9
Output: Final List = 5 <=> 3 <=> 1 <=> 9
The idea is to traverse the nodes of the doubly linked list one by one and get the pointer of the nodes having data even. Delete those nodes by following the approach used in this post.
Below is the implementation of above idea:
Original List: 15 16 7 6 17 Modified List: 15 7 17
Time Complexity: O(N), where N is the total number of nodes.
- Check whether the two Binary Search Trees are Identical or Not
- Johnson’s algorithm for All-pairs shortest paths | Implementation
- Code valid in both C and C++ but produce different output
- Sandvine Interview Experience for FTE 2018
- Sort the path from root to a given node in a Binary Tree
- Goldman Sachs Digital Interview Experience
- Sum of all nodes in a doubly linked list divisible by a given number K
- Delete all the nodes from a doubly linked list that are smaller than a given value
- How AI will affect our lives in next decade ?
- Convert List of Characters to String in Java
- Rat in a Maze | Backtracking using Stack
- Number of Counterclockwise shifts to make a string palindrome
- Stack Data Structure (Introduction and Program)
- Merge Sort for Linked Lists
- Check if the elements of stack are pairwise sorted
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.