我遇到了如何退出雙向鏈表中的循環,當它到達雙端結束時出現問題。如果在雙側存在一個元素,它將返回iter位置。如果沒有,它會在迭代結束時返回迭代器。我非常感謝你的幫助。謝謝在雙向鏈接列表中搜索
這裏是我的搜索功能
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;
}
旁註:你___really___確定要使用的已分配和管理的數據的智能指針? – Zeta
這不是我想要的東西,但這是我的教授要求我們做的: –
@Zeta相信我,[此代碼已經通過大量的ringers](http://stackoverflow.com/questions/19719529/doubly鏈接列表以及如何將迭代器移動到下一個節點) – WhozCraig