Delete_Node_2WayList(List,Value, Start, End)
Here in this algorithm List is a 2 way linked list containing n nodes. Start and End are the pointers pointing the starting and ending nodes. We have to delete a node from the list which contains Value as its data. Ptr is an intermediate pointer that will be used to traverse the list.
[Checking if List is Empty]
Step 1: if Start=null then
return;
[Initializing the Ptr]
Step 2: Ptr = Start
[Searching for the Node which is to be deleted]
Step 3: While Ptr <> null and Ptr->Data <> Value repeat the step
i) Ptr = Ptr -> Next
[Checking if search was successful or not]
Step 4: if Ptr = null then
return;
[Search was successful and Ptr is pointing to the node which is to be deleted]
Step 5: i) Ptr->Prev->Next = Ptr->Next [Next of Previous node of current node will point the next of current node]
ii) Ptr->Next->Prev = Ptr->Prev [Prev of Next node of current node will point the previous of current node]
[Now Current Node pointing by Ptr is not referenced from list anymore it can be freed now]
iii) FREE (Ptr)
Step 6: End;