In the remove function, you must update tail
if the list becomes empty.
int removeFirst()
{
List *nodeToRemove;
int dataToRemove;
if (head->next == NULL)
{
prtError("Empty list!");
return -1;
}
else
{
nodeToRemove = head->next;
dataToRemove = nodeToRemove->data;
head->next = nodeToRemove->next;
free(nodeToRemove);
// Update tail if list is empty
if (head->next == NULL)
{
tail = head;
}
return dataToRemove;
}
}
4
solved How to solve seg fault? [closed]