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:
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
if (Item == listPtr->item)
{ return true;
listPtr = listPtr->next;
}
else
{// Search for node in rest of list
loopPtr = listPtr;
while (loopPtr->next->item != Item)
loopPtr = loopPtr->next;
return true;
}
}
error: 32 C\ListType.cpp assignment of data-member `List::listPtr' in read-only structure