public class 单链表逆序 { public static class Node{ public int value; public Node next; public Node(int data) { this.value = data; } } public static void main(String[] args) { // TODO Auto-generated method stub Node head = null; head = new Node(1); head.next = new Node(2); head.next.next = new Node(3); head.next.next.next = new Node(4); printLinkedList(head); head = reserveLink(head); printLinkedList(head); } private static Node reserveLink(Node head) { if(head == null) { return null; } Node pre = null; Node next = null; while(head != null) { next = head.next; head.next = pre; pre = head; head = next; } return pre; } private static void printLinkedList(Node head) { while(head != null) { System.out.print(head.value+" "); head = head.next; } System.out.println(); } }