I'm using a simple linked list class and have found that the delete statement is causing a seg fault- the program using it periodically calls the clear function, and on certain inputs the program crashes at the delete statement. I have no idea what is causing it and would appreciate any suggestions~
bool clear()
{
bool isCleared=false;
Node * curNode=Head;
if(Head != NULL)
isCleared=true;
while(curNode != NULL)
{
Head=curNode->next;
delete curNode; <-------
curNode=Head;
}
curNode=NULL;
CurPos=-1;
SizeOf=0;
Current=NULL;
Head=NULL;
Tail=NULL;
return isCleared;
}
bool clear()
{
bool isCleared=false;
Node * curNode=Head;
if(Head != NULL)
isCleared=true;
while(curNode != NULL)
{
Head=curNode->next;
delete curNode; <-------
curNode=Head;
}
curNode=NULL;
CurPos=-1;
SizeOf=0;
Current=NULL;
Head=NULL;
Tail=NULL;
return isCleared;
}