我试图在我的链表中找到给定对象的索引。我想返回 -1 是我的列表中不存在该对象。以下是我的代码,请指导我。
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;
}