0

所以我正在尝试为名为 .dll 的 DLL 类编写一个函数MoveNextToBack。该函数的目的是将节点的下一个节点移动到列表的后面。到目前为止,这是我所拥有的,但我认为它并不完整:

void DLL::MoveNextToBack(Node *N){

    // If N's next node is the end already, return
    if(N->Next == Tail)
        return;

    // Change N's Next pointer to the one after N's current Next
    N->Next = N->Next->Next;

    // Change N's Next Next's Previous pointer to point to N
    N->Next->Next->Prev = N;

    // Move N to the end
    N->Next->Next = Tail;
    N->Next->Prev = Tail->Prev;

}

有什么我想念的吗?

4

1 回答 1

1

这应该工作

void DLL::MoveNextToBack(Node *N){

    // If N's next node is the end already, return
    if(N == NULL || N->Next == NULL || N->Next == Tail)
        return;

    //Pointer to the next node
    Node *tmp = N->Next

    //Point to the next, next node
    Node *pmt = N->Next->Next;

    // Change N's Next pointer to the one after N's current Next
    N->Next = pmt;

    // Change N's Next Next's Previous pointer to point to N
    if (pmt != NULL)
        pmt->Prev = N;

    // Move tmp to the end
    tmp->Prev = Tail;
    tmp->Next = Tail->Next;
    Tail->Next = tmp;
    Tail = tmp;
}
于 2013-10-09T02:44:16.513 回答