GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
70 views

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

asked in DS by Veteran (54.9k points)   | 70 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 (48.6k points)  
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 (14.7k points)  

Related questions

0 votes
1 answer
1
asked in DS by iarnav Active (1.4k points)   | 39 views
0 votes
2 answers
2
asked in DS by smartmeet Loyal (3.2k points)   | 205 views
0 votes
1 answer
3
asked in DS by smartmeet Loyal (3.2k points)   | 51 views


Top Users Jun 2017
  1. Bikram

    3912 Points

  2. Arnab Bhadra

    1550 Points

  3. Hemant Parihar

    1502 Points

  4. Niraj Singh 2

    1501 Points

  5. Debashish Deka

    1480 Points

  6. junaid ahmad

    1432 Points

  7. pawan kumarln

    1366 Points

  8. Arjun

    1246 Points

  9. Rupendra Choudhary

    1242 Points

  10. rahul sharma 5

    1240 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 26 - Jul 02
  1. pawan kumarln

    498 Points

  2. akankshadewangan24

    404 Points

  3. Arjun

    286 Points

  4. Debashish Deka

    234 Points

  5. Abhisek Das

    230 Points


23,435 questions
30,153 answers
67,633 comments
28,503 users