非递归实现逆转单链表,遍历单链表时,使用三个指针实现逆转:
public static Node reverseNode(Node node) {
if (null == node || null == node.next) {
return node;
}
Node pre = null;
Node cur = node;
Node next = null;
while (null != cur) {
next = cur.next;
cur.next = pre;
pre = cur;
cur = next;
}
return pre;
}