- private static Node head;
- public static void reverseLinkedList() {
- if(head == null || head.next == null) {
- return;
- }
- Node p1 = head;
- Node p2 = head.next;
- Node p3 = null;
- while(p2 = null) {
- p3 = p2.next;
- p2.next = p1;
- p1 = p2;
- p2 = p3;
- }
- head.next = null;
- head = p1;
- }
来源: http://www.bubuko.com/infodetail-2956396.html