I am trying to find an index of a given object in my linked list. I want to return -1 is the object doesn t exist in my list. Below is my code, please guide me.
int List::indexOf(const Object& o) const
{
Node* tempNode = first;
int count = 0;
while(tempNode != NULL)
{
if (o.compare(tempNode->o) == 0)
{
break;
}
++count;
tempNode = tempNode->next;
}
return count;
}