/********************************************
* Remove the last employee from the list *
********************************************/
void EmployeeList::Remove()
{
newEmployee * nextToEnd = head,
* last = head->Next();
//THIS IS THE PROBLEM
//no nodes
if(head == NULL)
return;
//remove the only employee in the list
if(head->Next()== NULL)
{
cout << "\n\t\tEmployee ID " << head->empID() << " and salary $"
<< head->ySalary() << " have been removed.\n";
head = NULL;
delete head;
}
else
{
// remove the last employee of the list
while(last->Next() != NULL)
{
nextToEnd = last;
last = last->Next();
}
cout << "\n\t\tEmployee ID " << last->empID() << " and salary $"
<< last->ySalary() << " have been removed.\n";
delete last;
nextToEnd->SetNext(NULL);
}
}
проблема возникает при попытке удалить из пустого списка. Я знаю, что я не могу удалить, если он пуст, но я бы вместо того, чтобы разбивать программу для отображения «Список сотрудников пуст.Функция удаления приводит к сбою программы C++
я указал, где я думаю, что проблема в надежде кого-то может помочь мне, чтобы понять это.
Что вы ожидаете от 'head-> Next()', если 'head' NULL? – immibis