1,232 views
0 votes
0 votes

Suppose p and q are 2 nodes in linked list, where p pointing to head node and q pointing to next to head node.

Now, chk this condition

while(A)
{
    if(p==q)exit(0);
    p=p->next;
    q=(q->next)?(q->next->next):q->next;
}

what is the meaning of line

 q=(q->next)?(q->next->next):q->next;

Can some body elaborate? Is it mean when q and q->next pointing to the same node, then q pointer should be incremented upto q->next->next?

And what should be value of A, so that this while loop satisfies the condition that this linked list satisfies the condition for a loop?

1 Answer

1 votes
1 votes
q=(q->next)?(q->next->next):q->next;

q is a pointer pointing to a linked list node, if the q->next is not NULL then pointer q will be assigned to second node after the node currently pointed by q, else q->next is NULL then q will be assigned to NULL.

I think, condition A should be p!=NULL && q!=NULL.

Related questions