3
I needed to switch two consecutive knots or not on a doubly linked list, but I can’t. Can someone help me? I’ve even done it on paper but it doesn’t perform. What’s wrong 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 switch of pointers, if it were simply chained list I could. Someone can help me?
Those last ones I tried on paper but I couldn’t 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;
}
Switch hands
prox
andant
or change content just enough?– Jefferson Quesado