Algorithm to Insert a Node at End
Algorithm to Insert a Node at End
1. Allocate the space for the new node and store data into the data part of the node and store
NULL at the address part of the node.
ptr->next=NULL
2. We need to declare a temporary pointer temp in order to traverse through the list. temp is
made to point to the first node of the list.
temp = ptr
temp = ptr;
while (temp -> next != NULL)
{
temp = temp -> next;
}
temp->next = ptr;
Algorithm
Step 1: IF PTR= NULL Write OVERFLOW
Go to Step 1
[END OF IF]
Step 2: SET NEW_NODE = PTR
Step 3: SET PTR = PTR - > NEXT
Step 4: SET NEW_NODE - > DATA = VAL
Step 5: SET NEW_NODE - > NEXT = NULL
Step 6: SET PTR = HEAD
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