Given a doubly linked list and a position n. The task is to delete the node at the given position n from the beginning.
Initial doubly linked list
Doubly Linked List after deletion of node at position n = 2
Approach: Following are the steps:
- Get the pointer to the node at position n by traversing the doubly linked list up to the nth node from the beginning.
- Delete the node using the pointer obtained in Step 1. Refer this post.
Doubly linked list before deletion: 10 8 4 2 5 Doubly linked list after deletion: 10 4 2 5
Time Complexity: O(n), in the worst case where n is the number of nodes in the doubly linked list.
This article is contributed by Ayush Jauhari. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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 a node in a Doubly Linked List
- Delete a Linked List node at a given position
- Delete all occurrences of a given key in a doubly linked list
- Delete all the nodes from the doubly linked list that are greater than a given value
- 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
- Insertion at Specific Position in a Circular Doubly Linked List
- Swap Kth node from beginning with Kth node from end 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
- Delete a given node in Linked List under given constraints
- Construct a Doubly linked linked list from 2D Matrix
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Delete Nth node from the end of the given linked list
- Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
- Find the largest node in Doubly linked list
- Create new linked list from two given linked list with greater element at each node