Created
July 23, 2014 03:13
-
-
Save stanley-shi/23e56ebfc09781801cb0 to your computer and use it in GitHub Desktop.
RevertLinkedList
This file contains 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 Class RevertLinkedList{ | |
public static class LinkedNode{ | |
int data; | |
LinkedNode next; | |
} | |
public LinkedNode revert(LinkedNode head){ | |
LinkedNode result = null; | |
while(head!=null){ | |
LinkedNode tmp=head.next; | |
head.next=result; | |
result = head; | |
head=tmp; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is purely an interview question;