Home » Deletion in Singly Linked List at Beginning

Deletion in Singly Linked List at Beginning

by Online Tutorials Library

Deletion in singly linked list at beginning

Deleting a node from the beginning of the list is the simplest operation of all. It just need a few adjustments in the node pointers. Since the first node of the list is to be deleted, therefore, we just need to make the head, point to the next of the head. This will be done by using the following statements.

Now, free the pointer ptr which was pointing to the head node of the list. This will be done by using the following statement.

Algorithm

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

  • Step 2: SET PTR = HEAD
  • Step 3: SET HEAD = HEAD -> NEXT
  • Step 4: FREE PTR
  • Step 5: EXIT

DS Deletion in singly linked list at beginning

C function

Output

1.Append List  2.Delete node  3.Exit  4.Enter your choice?1    Enter the item  23    Node inserted    1.Append List  2.Delete node  3.Exit  4.Enter your choice?2     Node deleted from the begining ...  

Next Topic#

You may also like