It's because you don't actually re-link the nodes, so you get an infinite loop. You need to change the next
link of the previous node as well as the prev
link on the next-next node.
If your list is doubly-linked, and you have a previous pointer and a next pointer, then you can do something like this:
node* next = temp->next;
// Fix the links of the previous node, and the next-next node
if (temp->prev)
temp->prev->next = next;
if (next->next)
next->next->prev = temp;
// Relink the two nodes that should be swapped
temp->next = next->next;
next->next = temp;
next->prev = temp->prev;
temp->prev = next;