+1 vote
153 views

How D) could be answer here?

I think for head->next=temp; will not work properly. Am I doing any mistake?

in DS | 153 views
0
i think D must be the answer...

here we will store the next node ddress and point to first present node to the previous....
0

1->2->3

Now according to code if we put option 4)

next=2

Now,

these two line how working?

How reverse operation going? Can u tell me in short?

0

temp=NULL;

now again...

i suggest u to ....draw the diagram..and see t...

0
@hs

Means final one will be 3->2->1 ?

Not getting properly

plz help
0

@sresta...

here...

Procedure is like this....

. in original list head is pointig to 1 and  1 is pointing 2 and 2 is pointing to 3 and 3 is pointing to NULL...

In reversal...

1 will point to NULL...2 will point ot 1 and 3 will point to 2 and head will point to 3....

Note;-- draw the procedure it on paper then u will get it definite...

{

}

let us consider head is pointing to the current node

1. is the first node

now we have to do only change head->next=NULL

2.not the first node

now we have to assign head->next= // previous node so we have to keep track of the previous node so that assignment can be possible

that why we use the  *temp to store previous node that can be assigned to head->next   such that head->next=tmp

* for the first node temp is simply null

now initially if we assign head->next=temp then we cannot keep track of the current next node because my current next node link will be lost that's why it used *next to first store the link of the current next node and the update head->next=temp

after that the current node is stored in the temp and head is moved to the current next node

by (221 points)