Monday, 26 August 2013

Removing from middle of the linked list c++

Removing from middle of the linked list c++

i have a problem with my RemoveMid function in my linked list.. the code
seems ok and there's no syntax error, but when i call this function, the
program stops working.. i think there's something wrong with the logic of
the function. i hope you may help me to correct it. this is the
implementation of the RemoveMid function
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";
}

No comments:

Post a Comment