Linked List Trouble

Been working on a Linked List for class and I can't seem to fix this one last function. The extract function should search, find, and delete a link that matches some data value. It works when the data is the first item, but anything else causes it to crash. I've gone through and tried everything I could think of but it still won't work, so now I'm asking for help.

This is the basic structure:
1
2
3
4
5
6
7
8
9
10
11
12
  template <class T>
class LLVector
{
private:
    struct Link
    {
        T data;
        Link *next;
    };
    Link *head;
    Link *current;
    int size;


And here is the problem function:
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
28
29
30
31
//Deletes selected data value
template <class T>
void LLVector<T>::extract(T find)
{
    Link *prev;
    if(head->data != find)
    {
        current = head;
        do{
            if(current->data == find)
            {
                prev->next = current->next;
                delete current;
                size--;
            }
            else
                prev = current;
        }while(current = current->next);
    }
    else if(head->data == find)
    {
        current = head;
        head = current->next;
        delete current;
        size--;
    }
    else
    {
        //Nothing found to be extracted
    }
}
Topic archived. No new replies allowed.