Home » Deletion in Doubly Linked List at The End

Deletion in Doubly Linked List at The End

by Online Tutorials Library

Deletion in doubly linked list at the end

Deletion of the last node in a doubly linked list needs traversing the list in order to reach the last node of the list and then make pointer adjustments at that position.

In order to delete the last node of the list, we need to follow the following steps.

  • If the list is already empty then the condition head == NULL will become true and therefore the operation can not be carried on.
  • If there is only one node in the list then the condition head → next == NULL become true. In this case, we just need to assign the head of the list to NULL and free head in order to completely delete the list.
  • Otherwise, just traverse the list to reach the last node of the list. This will be done by using the following statements.
  • The ptr would point to the last node of the ist at the end of the for loop. Just make the next pointer of the previous node of ptr to NULL.

free the pointer as this the node which is to be deleted.

  • Step 1: IF HEAD = NULL
  • Write UNDERFLOW
    Go to Step 7
    [END OF IF]

  • Step 2: SET TEMP = HEAD
  • Step 3: REPEAT STEP 4 WHILE TEMP->NEXT != NULL
  • Step 4: SET TEMP = TEMP->NEXT
  • [END OF LOOP]

  • Step 5: SET TEMP ->PREV-> NEXT = NULL
  • Step 6: FREE TEMP
  • Step 7: EXIT

Deletion in doubly linked list at the end

C Function

Output

1.Append List  2.Delete node from end  3.Exit  4.Enter your choice?1    Enter the item  12    Node Inserted  1.Append List  2.Delete node from end  3.Exit  4.Enter your choice?1    Enter the item  90    Node Inserted  1.Append List  2.Delete node from end  3.Exit  4.Enter your choice?2    Node Deleted  

Next TopicDoubly Linked List

You may also like