0

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
}
3
Contributors
3
Replies
5
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

Use your debugger and put a breakpoint on line 15 of the code you posted.
When the breakpoint is hit, examine the various variables.

0

I do not quite know how to use the debugger. Do I just mark the line and then select debug?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.