Created
April 22, 2015 20:05
-
-
Save orhanobut/de19bcbb9524042d184e to your computer and use it in GitHub Desktop.
Reverse singly list in place
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Node reverse(Node root){ | |
if (root == null) return null; | |
Node p = null; | |
Node n = root; | |
while (n != null){ | |
Node t = n.next; | |
n.next = p; | |
p = n; | |
n = t; | |
} | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment