I am not sure what I am doing incorrectly but when I step through with the debugger after selecting "delete head" it still retains its original address:
Code:
....
void DeleteAllNodes()
{
int test=0;
current = head;
if(!head)
return;
if(WC.bDebug)
{
fprintf(fpDebug, "\nDeleteAllNodes from head to tail.\n");
}
while(1)
{
temp = head;
if(head->next == 0)
break;
head = head->next;
if(WC.bDebug)
{
fprintf(fpDebug, "Delete %4d current = %9p prev = %9p\n", test, temp, temp->prev);
fflush(fpDebug);
}
delete temp;
test+=1;
}
if(WC.bDebug)
{
fprintf(fpDebug, "Delete %4d head = %9p prev = %9p\n", test, temp, temp->prev);
fflush(fpDebug);
}
delete head;
return; // head still has its original address!!!
}
The node head is not set to zero.
This really screws me up in my next call because I use head to control my creation of the new linked list.
Code:
if (! head )
{
head = new node;
tail = current = head; // set current and tail = to head
current->next = 0; // set next node to zero.
current->prev = 0; // set prev node to zero or possibly set to tail!!!
Do you see anything wrong with how I am calling delete?