I've got a singly linked list, and the following code is supposed to delete all nodes that are ranked as "Trainee", it deletes them all, but if the last node is a "Trainee", it will not delete it, why is that?
void LinkedList::removeLowest()
{
Soldier * ptrDelete;
ptrCurrent = ptrHead;
while(ptrCurrent != NULL)
{
if(!strcmp(ptrCurrent->getRank(), "Trainee"))
{
ptrCurrent->Show();
ptrDelete = ptrCurrent;
ptrCurrent = ptrCurrent->ptrNext;
delete ptrDelete;
}
else
{
ptrCurrent = ptrCurrent->ptrNext;
}
}
cout << "\nTrainees Sacked!";