In this tutorial, we are going to learn how to perform deletion operations in the doubly linked list.
after completing this tutorial you are able to learn how to
- Delete the first node.
- Delete the only node.
- Delete a node in between the nodes.
- Delete the last node.
Deletion of the first node from the doubly-linked list
as you see we have a doubly-linked list that has four nodes. so after deleting the first node second node become the first node.
Delete the only node from the doubly linked list.
if a linked list has only one node then to delete this node we set the start variable to the None.
so now our list becomes an empty list.
Delete a node in between the nodes.
to delete a node between two nodes first we need to find out the reference to the node that we want to delete. as you see to delete the third node first we found a reference p to that node.
Delete the last node from the doubly linked list
to delete the last node of the list first we need to find out the reference of the last node.