You're making this incredibly hard on yourself. Your code has a number of problems, including:
- failure to properly wire the previous pointers
- failure to account for a last-node deletion.
- failure to advance the head pointer if it was the prospect node.
Considering that, I think this does what you want, and I strongly advise you to examine it carefully, even stepping through it in a debugger to see how it works.
void delnode(const std::string& moviename)
{
// pp holds the address of the pointer that will
// eventually point to our node being deleted.
node **pp = &head;
// skip nodes until we find a match
while (*pp && (*pp)->title.compare(moviename))
pp = &(*pp)->next;
if (*pp)
{
node *tmp = *pp;
if ((*pp = tmp->next)) // assignment-eval intentional
(*pp)->previous = tmp->previous;
delete tmp;
}
}
This solves a number of issues, including
- properly updating the head pointer if it was the node matching your string.
- properly wiring
next
andprevious
to all proper pointers - properly removing the last node in the list if that is your suspect node.
- doing absolutely nothing if the head pointer is null.