Last active
March 31, 2016 18:31
-
-
Save flasher297/df657c39fa979dee2ca5adb43b847d1e to your computer and use it in GitHub Desktop.
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
private static final class Link | |
{ | |
String data; | |
Link next = null; | |
Link(String o, Link n) { | |
data = o; | |
next = n; | |
} | |
} | |
private static Link reverted = null; | |
public static void main(String[] args) | |
{ | |
Link fifth = new Link("5", null); | |
Link fourth = new Link("4", fifth); | |
Link third = new Link("3", fourth); | |
Link second = new Link("2", third); | |
Link first = new Link("1", second); | |
revert(first); | |
} | |
private static void revert(Link item) | |
{ | |
if (reverted == null) | |
{ | |
reverted = item; | |
Link temp = item.next; | |
reverted.next = null; | |
revert(temp); | |
} | |
else | |
{ | |
Link next = item.next; | |
item.next = reverted; | |
reverted = item; | |
if (next != null) { | |
revert(next); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment