Inserting a Node in Sorted List
Procedure to insert a new node in a sorted linked list.
Procedure :
Create a new node and assign the data to it.
Check if the head node is NULL. If it is, no nodes are present in the linked list and the new node will be the head.
Check if the head node's data is greater than the data to be inserted. If so, the new node will become the head node.
If nodes are already present, reach the proper position by checking if the data of next node in each iteration is less than the data to be inserted.
Once the position is reached, set the next of new node to be the next of current node.
Finally, set next of current node to new node.
Contributed by Nitin Ranganath
Last updated