SortedInsert() is a function which given a list that is sorted in increasing order, and a
single node, inserts the node into the correct sorted position in the list.I know this code works fine.I am just curious to know why we can't use just single pointer to node to traverse the string.why can't we use struct node * currentref.Just explain me how this works.
void SortedInsert(struct node** headRef, struct node* newNode) {
struct node** currentRef = headRef;
while (*currentRef!=NULL && (*currentRef)->data<newNode->data) {
currentRef = &((*currentRef)->next);
}
newNode->next = *currentRef; // Bug: this line used to have
// an incorrect (*currRef)->next
*currentRef = newNode;
}