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 (53.8k 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 (47k 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.6k points)  

Related questions

0 votes
1 answer
1
asked ago in DS by iarnav Active (1.1k points)   | 13 views
0 votes
2 answers
2
asked in DS by smartmeet Loyal (3.1k points)   | 129 views
0 votes
0 answers
3
asked in DS by smartmeet Loyal (3.1k points)   | 39 views


Top Users May 2017
  1. akash.dinkar12

    3292 Points

  2. pawan kumarln

    1652 Points

  3. sh!va

    1650 Points

  4. Arjun

    1424 Points

  5. Bikram

    1372 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    904 Points

  10. srestha

    718 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    458 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    278 Points

  4. Ahwan

    236 Points

  5. bharti

    194 Points


22,786 questions
29,121 answers
65,184 comments
27,661 users