in Tutorials/MemoryUsage/Stage1/main.c [161:187]
static void DeleteLastNode(Node **headNode)
{
if (*headNode == NULL) {
Log_Debug("\nThe list is empty...\n");
return;
}
listSize--;
Log_Debug("\nDeleting the last node from the linked list (list size = %u).\n", listSize);
// If the list contains just one node, delete it
if ((*headNode)->next == NULL) {
free(*headNode);
*headNode = NULL;
return;
}
// Find the second last node
Node *secondLast = *headNode;
while (secondLast->next->next != NULL) {
secondLast = secondLast->next;
}
free(secondLast->next);
secondLast->next = NULL;
}