My Remove() node function does not work

I'm trying to remove one node from a linked list. I'm able to locate the node but the remove function does not work, it keeps returning false. Please take a look. Thank you.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
bool list::remove(string first, string last) 
{

    if (head == nullptr) return false;

    node *temp = head;

    if (temp->first == first && temp->last == last)
    {
        head = temp->next;
        delete temp;
        return true;
    }
    node *temporal = temp->next;
    while (temporal) 
    {
        if (temporal->first == first && temporal->last == last) 
        {
            temp->next = temporal->next;
            delete temporal;
            return true;
        }
        temp = temporal;
        temporal = temporal->next;
}
return false;
}

Last edited on
Topic archived. No new replies allowed.