I understood this concise way of reversing linked list from source "BlogSpot - Reverse a linked list using only 2 pointers" and I tried to convert this into Java but getting logical error. Can any one provide me with correct implementation ?
C++ version
while(q)
{
q = (List*) ((int)p ^ (int)q ^ (int)q->next ^ (int)(q->next=p) ^ (int)(p=q));
}
head = p;
Java Version
Below approach is wrong.
while(q!=null)
{
q = new ListNode(p==null?0:p.val ^ q.val ^(q.next==null?0:q.next.val)^((q.next==null?0:(q.next.val =p.val)))^(p.val=q.val));
}