Поэтому я пытаюсь написать функцию для класса DLL с именем MoveNextToBack
. Назначение функции - переместить узел следующего узла в конец списка. Вот что я до сих пор, но я не думаю, что это завершено:
void DLL::MoveNextToBack(Node *N){
// If N next node is the end already, return
if(N->Next == Tail)
return;
// Change N Next pointer to the one after N current Next
N->Next = N->Next->Next;
// Change N Next Next 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;
}
Что-нибудь мне не хватает?
Это должно работать
void DLL::MoveNextToBack(Node *N){
// If N 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 Next pointer to the one after N current Next
N->Next = pmt;
// Change N Next Next 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;
}