我在中间位置之后插入节点时遇到问题,即使我检查了指向指针的所有链接并且它们都是正确的,仍然有未处理的异常。有人可以看看我的代码,看看出了什么问题吗?
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++;
}
}
}