Logic:
sort_addnode(data) function will add the data to linked list
in sorted manner.
for first node , It will assign head pointer to it.
After that we are comparing node info with new node's info.
we have maintained Predecessor pointer for our new node.
Look below figure
After that it will be easy to add new node.
sort_addnode(data) function will add the data to linked list
in sorted manner.
for first node , It will assign head pointer to it.
After that we are comparing node info with new node's info.
we have maintained Predecessor pointer for our new node.
Look below figure
Sorted manner Insertion |
After that it will be easy to add new node.