struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
Input is 1 2 3 4 5 6 7 what would be the output plrase explain
the output should be
2 1 4 3 6 5
because intially p is address for first node (which has value 1 at present) and q is the address of 2nd node (which has value of 2 at present)
in first pass:-
we swap value in p and q // LL : 2 1 3 4 5 6
now p =q->next this means p is the address of 3rd node (which has val of 3 right now) and q is q=p->next which is 4th node address having value as 4 in it.
in second pass:
we again swap p and q’s value // LL : 2 1 4 3 5 6
we have p as 5th node address and q as 6th node address
in third pass
we have we swap : // LL : 2 1 4 3 6 5
p is NULL and since p is NULL we have q also null because of ?: operation
and we break out of the loop
and we get out final state of linked list as // LL : 2 1 4 3 6 5
In case of any doubt feel free to ask 
Mark your doubt as resolved if you got the answer