doubly linked listt

I have problem solving doubly linked list in c++, i have pseudo code for function who finds element, so can someone help me?

struct element {
int key;
element *prev, *next;
};

function FIND(head, key)
begin
current:=head;
while current<>NIL and current.key <> key do
current:=current.next;
end
return current;
end
1
2
3
4
5
6
7
8
9
element* find(element* head, int key)
{
    element* current = head;
    while (current != nullptr && current->key != key)
    {
        current = current->next;
    }
    return current;
}
Thanks, it helped
Registered users can post here. Sign in or register to post.