简单常用算法 发表于 2015-01-01 单链表反转1234567891011121314151617181920212223242526272829303132class Node { Node(int v, Node n) { this.val = v; this.next = n; } int val; Node next;}public class App { public static Node reverse(Node node) { Node pre = node; Node cur = node.next; Node tmp; while (cur != null) { tmp = cur.next; cur.next = pre; pre = cur; cur = tmp; } node.next = null; return pre; } public static void main(String []args) { Node node = new Node(1, new Node(2, new Node(3, new Node(4, null)))); Node res = reverse(node); while (res != null) { System.out.print(res.val + "->"); res = res.next; } }} 结果: D:\B\A>javac App.java D:\B\A>java App4->3->2->1->D:\B\A> 快速排序