Deletion in Circular doubly linked list at beginning
There can be two scenario of deleting the first node in a circular doubly linked list.
The node which is to be deleted can be the only node present in the linked list. In this case, the condition head → next == head will become true, therefore the list needs to be completely deleted.
It can be simply done by assigning head pointer of the list to null and free the head pointer.
in the second scenario, the list contains more than one element in the list, therefore the condition head → next == head will become false. Now, reach the last node of the list and make a few pointer adjustments there. Run a while loop for this purpose
Now, temp will point to the last node of the list. The first node of the list i.e. pointed by head pointer, will need to be deleted. Therefore the last node must contain the address of the node that is pointed by the next pointer of the existing head node. Use the following statement for this purpose.
The new head node i.e. next of existing head node must also point to the last node of the list through its previous pointer. Use the following statement for this purpose.
Now, free the head pointer and the make its next pointer, the new head node of the list.
in this way, a node is deleted at the beginning from a circular doubly linked list.
[END OF LOOP]
1.Append List 2.Delete Node from beginning 3.Exit 4.Enter your choice?1 Enter the item 12 Node Inserted 1.Append List 2.Delete Node from beginning 3.Exit 4.Enter your choice?2 Node Deleted