Insertion in doubly linked list at beginning
As in doubly linked list, each node of the list contain double pointers therefore we have to maintain more number of pointers in doubly linked list as compare to singly linked list.
There are two scenarios of inserting any element into doubly linked list. Either the list is empty or it contains at least one element. Perform the following steps to insert a node in doubly linked list at beginning.
Since, the node being inserted is the first node of the list and therefore it must contain NULL in its prev pointer. Hence assign null to its previous part and make the head point to this node.
Enter the item which you want to insert? 12 Press 0 to insert more ? 0 Enter the item which you want to insert? 23 Press 0 to insert more ? 2
Enter the item which you want to insert? 12 Press 0 to insert more ? 2