Write an algorithm “Insert At Mid Point” in doubly link list.

Algorithm:

Insert (node head, value)
1. [Start]
2. [Check condition]
If head=null OR head->next=null then
Show “cannot be inserted.”
Else
Node ptr=head
2.1 [Repeat loop]
While ptr<>null
Count++
Ptr=ptr->next
[End of loop step (2.1)]
Mid=count/2
Node temp
Temp->data=value
Ptr=head
2.2[Repeat loop]
While mid>0
Ptr=ptr->next
Mid–
[End of loop step (2.2)]
Temp->next=ptr->next
Temp->pre=ptr
Ptr->next->pre=temp
Ptr->next=temp
[End of if else step (2)]
3. [Return]

Leave a Reply

Your email address will not be published. Required fields are marked *