Algorithm for inserting a node at the End


Step 1: IF AVAIL = NULL 
      Write OVERFLOW 
      Go to Step 1 
      [END OF IF] 
Step 2: SET NEW_NODE= AVAIL
Step 3: SET AVAIL = AVAIL->NEXT 
Step 4: SET NEW_NODE->DATA = VAL
Step 5: SET NEW_NODE->NEXT= NULL 
Step 6: SET PTR = START 
Step 7: Repeat Step 8 while PTR->NEXT != NULL 
Step 8: SET PTR = PTR->NEXT [END OF LOOP] 
Step 9: SET PTR->NEXT=NEW_NODE
Step 10: EXIT

 

Explanation

  • Create memory block using malloc function. If malloc function are create memory then it will return address of this memory block. Otherwise memory overflow problem.
  • Created memory block assign data value and next pointer value.
  • Find last node and attach this newly created memory to end position. if linked list are empty then assign this address of root pointer of given linked list.