First time here? Checkout the FAQ!
+2 votes


I cannot understand how this portion of code working for reverse. Can somebody explain?

asked in DS by Veteran (64.8k points) 35 220 622 | 87 views

2 Answers

+4 votes
Best answer

1st iteration:


$2$nd iteration:

After one interation : edge between $Z$ and $X$ is reversed.

answered by Veteran (56.9k points) 36 189 498
selected by
good one :)
+3 votes
we have taken 3 pointers as
X, Y and Z.

i. X is pointing to Head
ii. Y pointing to the next node of X
initially Z is Null hence,

X->next = Z, will make head node last node

Z will point to the node pointed by X, and now X and Will point to the second node.

in next iteration
Y will point to 3rd node, 2nd node's pointer will point to the first node which was head earlier.
and so on..

PS: don't consider this part of code only, but consider the entire while loop
answered by Veteran (16.4k points) 15 134 252

Related questions

0 votes
1 answer
asked in DS by iarnav Loyal (4.6k points) 4 36 111 | 91 views
0 votes
2 answers
asked in DS by smartmeet Loyal (4.8k points) 4 44 88 | 557 views
0 votes
1 answer
asked in DS by smartmeet Loyal (4.8k points) 4 44 88 | 69 views

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23240 Points

  2. Bikram

    17038 Points

  3. Habibkhan

    7096 Points

  4. srestha

    6008 Points

  5. Debashish Deka

    5430 Points

  6. jothee

    4928 Points

  7. Sachin Mittal 1

    4762 Points

  8. joshi_nitish

    4278 Points

  9. sushmita

    3954 Points

  10. Rishi yadav

    3744 Points

Recent Badges

Popular Question neha singh
Notable Question tajar
Notable Question Imarati Gupta
Notable Question set2018
Popular Question jothee
Notable Question set2018
Notable Question Pavan Kumar Munnam
Notable Question iarnav
Popular Question makhdoom ghaya
Popular Question Satyam
27,254 questions
35,075 answers
33,185 users