2. • Removing a node from the linked list
• Deletion involves three cases :
• Case 1 : Delete the first node present in the list
• Case 2 : Delete the last node present in the list
• Case 3 : Delete any node present in the list
3. Delete the first node in the list
• Procedure:
• Check if the header points to NULL. If so, return “ no nodes present in
the list. Deletion is impossible.”
• Otherwise :
• 1. Delete the first node by altering the LINK Fields
• 2. The header node link field points to the second node in the list.
4.
5. Algorithm:
1. Ptr = HEADER LINK
2. If (Ptr = NULL ) then
3. print “ The list is empty: No deletion”
4. Exit
5. Else
6. Ptr1=ptrLINK
7. HEADERLINK = Ptr1
8. ReturnNode(Ptr)
9. Endif
10. Stop
6. Delete the last node:
• Procedure:
• Check if the header points to NULL. If so, return “ no nodes present in
the list. Deletion is impossible.”
• Otherwise :
• 1. Delete the last node by altering the LINK Fields
2. Take a variable called ptr1, store the current position in ptr and
compare the current node pointer points to NULL Value.
• 3. Remove the last node.
7.
8. Algorithm:
1. Ptr = HEADER LINK
2. If (Ptr = NULL ) then
3. print “ The list is empty: No deletion”
4. Exit
5. Else
6. While (ptr LINK != NULL) do
7. ptr1=ptr
8. ptr=ptrLINK
9. endwhile
10. ptr1LINK=NULL
11. endif
12. stop
9. Delete any node:
1. ptr1=HEADER
2. If(ptr1=NULL)
3. print “ no nodes in the list, deletion not possible”
4. Else
5. ptr=ptr1 LINK
6. while(ptr!= NULL) do
7. if(ptr DATA != KEY) then
8. ptr1=ptr
9. ptr=ptrLINK
10. else
11. ptr1LINK = ptrLINK
12. returnnode(ptr)
13. exit
14. endif
15. endwhile
16. Stop