Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Walk the list with three pointers: prev (initially null), curr (initially head), and next (saved before rewiring). At each step, point curr.next back to prev, then advance prev and curr forward. When curr is null, prev is the new head.
Each node is visited exactly once and its next pointer is redirected to the previous node. By the end of the traversal prev points to the last node visited, which is the new head of the reversed list.
Updated Feb 2026