I need help in understanding some example code. If you want to delete the last node of the list L, why does the parameter have to be a pointer to a variable containing a node pointer? In other words why is it **L? Is there any list example that would not have its last node deleted if the parameter had been only a node pointer as in the function prototype void DeleteLastNode(NodeType *L)
Code:
void DeleteLastNode(NodeType **L)
{
NodeType *PreviousNode, *CurrentNode;
if (*L!=NULL)
{
if ((*L)->Link == NULL)
{
free(*L);
*L=NULL;
}
else
{
PreviousNode=*L;
CurrentNode=(*L)->Link;
while (CurrentNode->Link!=NULL)
{
PreviousNode=CurrentNode;
CurrentNode=CurrentNode->Link;
}
PreviousNode->Link=NULL;
free(CurrentNode);
}
}
}