Okay, maybe I'm just overlooking something but I need help. I have this program that reads in some numbers from a file and makes a linked list. The only function that is not working properly is one I called IsThere. Basically, it's just supposed to tell me whether or not a specific number is in the list. It works fine as long as the number is in the list but if it is not, the program crashes. I can't figure out what I'm doing wrong. Below is the IsThere function from my implementation file and then I'll also include the line of code from my client code.
bool ItemList::IsThere(ItemType item) const
{
NodePtr newIsTherePtr;
newIsTherePtr = listPtr;
while (newIsTherePtr->item!=item)
{
newIsTherePtr=newIsTherePtr->next;
}
if(item==newIsTherePtr->item)
{
return true;
}
else
{
return false;
}
}
cout<<"Is 2000 an item in the list? "<<temp.IsThere(2000)<<endl;
cout<<"Is 78 an item in the list? "<<temp.IsThere(78)<<endl;
Note: 2000 is in the list so if I get rid of the second line, the program works fine. However, if I put a number in that is not in the list, the program crashes at this point. I know it has something to do with how I coded the function but I'm outta ideas...