I was seeing a code online to reverse a linked list, but i could not understand what is happening. I tried to simulate this with a linked list 1-->2-->3-->4-->null, but could not figure it out. Can anyone explain me?
This is what i understood for input 1-->2-->3-->4-->null
while loops till the time current pointer reached to the end of the list, i.e null
Aditya Sirohi wrote:So the above code that i pasted is correct?
The only way we could answer that question with any degree of certainty would be to compile, run, and test it - which is something YOU can do yourself, right? I would assume you already have it in a full working program. For one of us to test it, we'd have to write a bunch of code to drop this method into, which most people don't have the time to do.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I did not implement this piece of code inside my class yet. I wanted to traverse through the code with an input in mind and trace the output on the white board first, so that i get a solid understanding before i implement it myself in the code.