Algorithm: Let input linked list is sorted in increasing order. 1) If Linked list is empty then make the node as head and return it. 2) If value of the node to be inserted is smaller than value of head node then insert the node at start and make it head. 3) In a loop, find the appropriate node after which the input node (let 9) is to be inserted. To find the appropriate node start from head, keep moving until you reach a node GN (10 in the below diagram) who's value is greater than the input node. The node just before GN is the appropriate node (7).
Read full article from Given a linked list which is sorted, how will you insert in sorted way | GeeksforGeeks
No comments:
Post a Comment