I needed to swap two consecutive nodes or not in a double-chained list, but I can not. Can someone help me? I already did it on paper but it does not execute. What is the problem with the code?
void swap(no_teste* A, no_teste* B) {
no_teste* proximoA = A->prox;
no_teste* anteriorB = B->ant;
A->prox = B->prox;
B->ant = A->ant;
A->ant = anteriorB;
anteriorB->prox = A;
B->prox = proximoA;
proximoA->ant = B;
}
I get lost with this exchange of pointers, if it was simply chained list I would get it. Can anyone help me?
The last ones I tried on paper but could not even use them:
void init(no_teste* aA, no_teste* A, no_teste* bA, no_teste* aB, no_teste* B, no_teste* bB) {
aA = A->ant;
bA = A->prox;
aB = B->ant;
bB = B->prox;
}
void Disconect_Geral_Node(no_teste* aA, no_teste* A, no_teste* bA) {
aA->prox = NULL;
A->ant = NULL;
A->prox = NULL;
bA->ant = NULL;
}
void Geral_Conect(no_teste* aA, no_teste* B, no_teste* bA) {
aA->prox = B;
B->ant = aA;
B->prox = bA;
bA->ant = B;
}