running off the end of the list
I'm running off the list on my destructor.
Can someone tell me how to stop the while loop before this happens.
I made some adjustements to a prior posted code in regards to my program, but now when i'm destructing my list it seems like the while loop keeps running to far and goes off the list into garbage.
Is there a test i'm missing?
Code:
linklist::~linklist()
{
link *current;
if(head!=NULL)
{
current = head->next;
while (current != NULL)
{
x++;
cout << "delete node " << head->lname << endl;
delete head;
head = current;
current = current->next;
}
cout << "Deleting last node " << head->lname << endl;
delete head;
}
else
{
delete head, tail;
}
head=NULL;
tail=NULL;
current=NULL;
}