我的链表中的 RemoveMid 函数有问题。代码看起来没问题,没有语法错误,但是当我调用这个函数时,程序停止工作。我认为函数的逻辑有问题。我希望你能帮助我纠正它。这是 RemoveMid 函数的实现
template<typename T>
bool LinkedList<T>::RemoveMid(T& target)
{
Node<T> *current = new Node<T>;
bool found = false;
current = start;
while(current != NULL && !found)
{
if(current->next->info == target)
found = true;
if(!found)
current = current->next;
}
if(found)
{
Node<T> *Ptr;
Ptr = current->next;
current = current->next;
delete Ptr;
return true;
}
else
cout<<"target not found\n";
}