我有問題在一個間隔位置之後插入一個節點,保持未處理的異常,即使我檢查指向的所有鏈接,它們都是全對了。有人會看看我的代碼,看看有什麼問題嗎?在deque類中的一個位置後插入一個節點
void insert_after(DequeIterator<E>& iter, E x)
{
if(_size == 0)
{
insert_front(x);
}
else
{
assert(!iter.at_end());
// need to check, if its the iter is the last element
// do insert_back instead
if(iter.node() == _tail)
insert_back(x);
else
{
// create a temp2 pointer to hold the address of iter
DNode<E>* temp2 = iter.node();
// set temp2 equal to the address of the node after
// iter before inserting
iter.node()->next()->set_next(temp2);
// create a new node to insert
DNode<E>* temp = new DNode<E>(iter.node(), x, temp2);
// set the iter->next to hold the address of the new node
iter.node()->next()->set_next(temp);
//set the address of temp2->prev to hold the address
// of the new node.
// This is also where I got the exception error !!!!
temp2->prev()->set_prev(temp);
_size++;
}
}
}
這是你自己的deque實現嗎?如果那麼這將有助於查看該代碼,否則這段代碼並沒有太多說明。 – edorado