Insert node at beginning of Doubly linked list

That is very simple to add new created doubly linked list node at front (beginning) position. That are similar to single linked list but only the difference are this are contain two pointer fields. next and previous pointer. next pointer are hold the reference of next node of linked list and previous pointer are hold the reference of previous node.

Insertion approach: There is two cases to add doubly linked list node at front position. First is when linked list are empty, and we are insert first element of linked list. In this case created newly doubly linked list node and set this node pointer fields to (next and previous) NULL. and assign this node address to head (head pointer) of linked list.

When linked list are not empty then create a doubly linked list node and this node next pointer are assign the address of first node of linked list (Note that head pointer are holds the reference of first node).

And this head node previous pointer field are assign newly created node and new created node next pointer is assign to head of linked list. after that provide this new node reference to head pointer.

Suppose we are inserted the following (80,70,60,50,40,30,20,10) node in a sequence.

insertion node at beginning

Here given code implementation process.

In this above example doubly linked list are accessed by first node. Observed that in case we are have one more variable which are point to last node then we can access both direction of linked list.



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved