我必須構建一個函數,其目的是在由DequeIterator類管理的iter位置之前/之後插入一個節點。爲了做到這一點,我必須將所有指針鏈接到正確的位置,以使它們彼此連接,然而,我有問題將所有指針鏈接到正確的節點。在雙向鏈表中間插入節點
例如,如果我有一個雙向鏈接的節點A,B,D,E的列表,並且我的iter現在指向節點D,並且我想在節點D之前插入一個節點C.是否有人幫幫我 ?謝謝
// iter will be an object from the DequeIterator.
void insert_before(DequeIterator<E>& iter, E x)
{
// make sure the list is not empty
// since I have a function insert_front already
assert(!is_empty());
// create a temp pointer to hold node D
DNode<E>* temp = iter.node();
// create a new node C, with its prev points to (D->prev)
// and its next points to node C
DNode<E>* temp2 = new DNode<E>(iter.node()->prev(), x, iter.node());
// I know that I still have 2 more pointer to link
// but I do not know how to get it connected from
// node B to node C and node C to node D.
iter.node()->next() = temp2; // I attempted to do this, but it gave me an error
_size++;
}
這是錯誤我有
Error 1 error C2106: '=' : left operand must be l-value e:\fall 2013\cpsc 131\linkeddeque\linkeddeque\main.cpp 312
你會得到什麼錯誤? –
我確實犯了我得到的錯誤。謝謝 –