387 views
2 votes
2 votes

what should be the statement at A

1 Answer

2 votes
2 votes

It will run until is actually at null.

hence A : q!=NULL

How ?

Let us take 3 nodes in a link list with no looping. nodes are A-->B-->C.

initially head is at A.

p=A

q=B.

Inside the loop,

it will increment p. hence now p = B.

next condition is

if(q->next)

   q = q->next->next;

else

   q= q->next.

Hence q->next = B->next = C it is true.

Hence q = q->next->next

q = NULL.

At this point no loop will be detected and hence code should be stop.

Hence condition A = q!=NULL.

Related questions

0 votes
0 votes
1 answer
2
Souvik33 asked Nov 2, 2022
865 views
Which data structure would be most appropriate to implement a collection of values with the following 3 characteristicsSingly link list with head and tail pointerDoubly l...
1 votes
1 votes
2 answers
3
srestha asked Sep 11, 2017
1,257 views
1) What is the algorithm for reversing the singly linked list?2) How palindrome could be made with the help of this algo ?