We have got this code in order to insert a value into a list sorted
Code:
void insertValue(node *newNode)
{
node *curr, *prev;
curr = nodeHead; // nodeHead is a global
prev = NULL;
// Scan for place to insert (sorted numerically)
while (curr && curr->data < newNode->data)
{
prev = curr;
curr = curr->next;
}
// Update pointers
newNode->next = curr;
newNode->prev = prev;
if (prev == NULL)
nodeHead = newNode;
else
prev->next = newNode;
if (curr == NULL)
nodeTail = newNode;
else
curr->prev = newNode;
}
Why the code works also without the last if statement?
can anyone tell me what is nodetail(probably is the last node of the list)
in the main program there is no where decleration of nodetail.
Thanks