您将如何在非模板化 C++ 链表中实现查找函数?
remove 函数的实现方式如下:
bool LinkedList::remove(Node* n)
{
Node *temp = front, *prev = 0;
for(int i = 0;i < size; i++)
{
if (temp == n)
{
if (temp == front)
{
front = n->next;
}
else
{
prev->next = temp->next;
}
delete temp;
size --;
return true;
}
prev = temp;
temp = temp->next;
}
return false;
}