Z
zfareed
I am attempting to search a list to check whether an item is already
present before inserting. I am having trouble with the pointers; I
understand that I need to set the pointer to the start of list but I
keep getting compilation errors. Can anyone help? Here is my code:
<code>
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
loopPtr = listPtr;
if (Item == listPtr->item)
return true;
else
{// Search for node in rest of list
while (loopPtr->next->item != Item)
loopPtr = loopPtr->next;
return true;
}
return false;
}
</code>
the program crashes on execution
present before inserting. I am having trouble with the pointers; I
understand that I need to set the pointer to the start of list but I
keep getting compilation errors. Can anyone help? Here is my code:
<code>
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
loopPtr = listPtr;
if (Item == listPtr->item)
return true;
else
{// Search for node in rest of list
while (loopPtr->next->item != Item)
loopPtr = loopPtr->next;
return true;
}
return false;
}
</code>
the program crashes on execution