Quote Originally Posted by a0161 View Post
Thank you for providing pseudo-code

Now I got there are another conditions that I didn't consider.
The code I made does not cover every condition.
You have covered the most generic case; now for specific cases where either or both the nodes to be swapped have a NULL pointer for their previous or next node. Those can be covered by a number of if-else statements as iMalc said in his post. If say D was the last element in the doubly linked list then its *next pointer would be NULL as in
Code:
/* check if *next is not NULL */
if (ptr_to_D->next)
    ptr_to_D->next->prev = ptr_to_B