I'm having problem on how to get out of the loop in a doubly linked list when it gets to the end of the deque. If there is an element in the deque, it will return the iter position. If not, it will return the iterator at the end of the deque. I'd really appreciate your help. Thank you

Here is my search function

unique_ptr<DequeIterator<E>> find(E match)
{
    assert(!is_empty());

        // the iter will begin from the head.
    unique_ptr<DequeIterator<E>> iter(iter_begin());

        // Here is where I do not know how to get it quit when 
        // it gets to the end of the deque.
        // ALSO it needs to check the value at the end of
        // the deque before it quits too.
    while(iter->value() != match)
    {
        iter->next();
    }
    return iter;
}
有帮助吗?

解决方案

Surely just something like:

while( iter != iter_end() && 
       iter->value() != match )
{
    iter->next();
}

return iter;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top