Input : 0->1->2->3->4->5->6->7->8->9->

output: 1->0->3->2->5->4->7->6->9->8->

Code :

        public void SwapEverySecondElement()
        {
            var p = head;
            var q = p.Next;

            while (q != null)
            {
                var temp = p.Data;
                p.Data = q.Data;
                q.Data = temp;
                p = q.Next;
                if (p != null)
                {
                    q = p.Next;

                }
                else
                {
                    q = null;
                }

            }

        }

Test

Input

0->1->2->3->4->5->6->7->8->9->

Output

1->0->3->2->5->4->7->6->9->8->

——————————————————————————–

Input

A->B->C->D->E->F->G->H->I->J->K->L->M->N->O->P->Q->R->S->T->U->V->W->X->Y->Z->

Output

B->A->D->C->F->E->H->G->J->I->L->K->N->M->P->O->R->Q->T->S->V->U->X->W->Z->Y->