经典算法(三) 单链表 反转 & 是否相交/成环 & 求交点 等
参考文章: 判断链表是否相交: http://treemanfm.iteye.com/blog/2044196 一、单链表反转 链表节点 public class Node { private int record; private Node nextNode; public Node(int record) { super(); this.record = record; } } View Code 构建链表 public static Node creatLinkedList() { Node head = new Node(0); Node tmp = null; Node cur = null; for (int i = 1; i < 10; i++) { tmp = new Node(i); if (1 == i) { head.setNextNode(tmp); } else { cur.setNextNode(tmp); } cur = tmp; } return head; } View Code 递归实现 public static Node reverse(Node head) { if (null == head || null == head.getNextNode()) { return head; } Node reversedHead =