Algorithm for swapping two nodes in a doubly lineked list.
I'm trying to swap two nodes in a doubly linked list and I'm going nutzo trying to get it right.
Here's the algorithm that I've written.
Please note: I can't just change the data. I tried that and the instructor projetile vomited the work back to me and told me "go home and swap them pointers boy!".
Anyway, I've been working on this since last night to no avail. can someone assist?
thanks in advance.
POS1, POS2 and temp are all nodes of the same type.
temp = POS2;
POS1->Prev = POS2->Prev;
POS1->Next = POS2->Next;
POS2->Prev = POS1;
POS2->Next->Prev = POS1;
temp->Next = POS1->Next;
temp->Prev = POS1->Prev;