//! deep copy, Copy constructor. Makes a complete copy of its argument
LinkedList::LinkedList(const LinkedList & other)
{
Clear();
first=NULL;
last=NULL;
if(!other.IsEmpty())
{
LLNode* otherPointer = other.first;
while(otherPointer!=NULL)
{
Insert(otherPointer->value ,GetLast());
otherPointer=otherPointer->GetNext();
}
}
}
//! Removes all values from the list
void LinkedList::Clear()
{
if(first!=NULL)
deleteAll(first);
size=0;
}
void LinkedList::deleteAll(LLNode* node)
{
if (node->next!=NULL)
deleteAll(node->next);
delete node;
}
It keeps seg faulting at the (if node->next!=NULL) because for some reason the condition for if(first!=NULL) doesn't work for this empty list. Why? Any tips or suggestions on how to clean this up so that my conditions work would be aprreciated
Oh, PS this post was called fixing up memory leaks because if I don't call delete node; it works just fine.

New Topic/Question
Reply



MultiQuote











|