The below is my code to recursive swap the adjacent elements of a linked list. I am losing the pointer to every second element after the swap. The input is 1->2->3->4->5->6-
Using recursion:
void nodelist::swap(node** head) { if (!*head || !(*head)->next) return; node* const sw = (*head)->next; (*head)->next = sw->next; sw->next = *head; *head = sw; swap(&(sw->next->next)); }