Z
zfareed
I have this function that searches a link list before main performs
the insert function to insert an item. My problem is the pointer stuff
and the program keeps crashing.
<code>
List::List()
{
listPtr = NULL;
}
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
loopPtr = listPtr;
while(loopPtr != NULL) // but listPtr is NULL- is this the
problem
{
if(loopPtr->item == Item)
return true;
else
{
loopPtr = loopPtr->next;
}
return false;
}
}
// this is the declaration in the spec file
private:
NodeType* listPtr;
int length;
</code>
Can anyone help?
the insert function to insert an item. My problem is the pointer stuff
and the program keeps crashing.
<code>
List::List()
{
listPtr = NULL;
}
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
loopPtr = listPtr;
while(loopPtr != NULL) // but listPtr is NULL- is this the
problem
{
if(loopPtr->item == Item)
return true;
else
{
loopPtr = loopPtr->next;
}
return false;
}
}
// this is the declaration in the spec file
private:
NodeType* listPtr;
int length;
</code>
Can anyone help?