反转单向链表

937 Java , 一条评论
以Java语言为主,实现如下: public class Node { public int value; public Node next; public Node(int value) { this.value = value; } public Node reverseList(Node head) { Node prev = null; // 用于暂存前面的节点 Node next = null; // 用于暂存后面的节点 while (head != null) { next = head.next; // 把后面的节点暂存起来 …