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.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.