Can someone help me with my delete function? I am having trouble figuring out why my delete function is not reporting false when attempting to delete a bank id that
does not exist. Thanks.
bool Bank::RemoveBankNumber(int bankID)
{
Bank *temp, *back;
if (head == NULL) return false;//(isEmpty()) return;
// Search the list for the item to delete
temp = head;
back = NULL;
while((temp != NULL) && ( temp->getbankID() != bankID ))
{
back = temp;
temp = temp->next;
}
// Check to see if the item was found
if(temp == NULL) return false; // Not found so return false
else if(back == NULL) // Check to see if item is first in list
{
head = head->next;
delete temp; // Dispose of the node removed from the list
}
else // Delete node elsewhere in the list
{
back->next = temp->next;
delete temp; // Dispose of the node removed from the list
}
return true; // Signal successful deletion
}