In the given doubly linked list, delete a node
We can delete head node, middle node or last node.
Time complexity : O(1)
Step 1 : create a function which takes a linked list and node that had to be deleted as arguments and delete the node.
Step 2 : If you want to delete a head node.
a) Change the head pointer to next of current node (head here).
b) Change the previous pointer of next node to current node previous.
Step 3 : If you want to delete middle node.
a) Change the previous pointer of next node to current node previous
b) Change the previous node next pointer to next of current node.
c) Delete the node. (current node)
d) If previous or next is NULL you need not delete them. (for deleting last node)
Step 4 : On the given linked list, call the function and give which node you want to delete.