单链表反转 遍历法Java实现
发布于 2020-04-29 17:58:05
关注者
1
被浏览
1023
1 个回答
-
static Node reverseLinkedList(Node node) { Node previousNode = null; Node currentNode = node; Node headNode = null; while (currentNode != null) { Node nextNode = currentNode.next; if (nextNode == null) { headNode = currentNode; } currentNode.next = previousNode; previousNode = currentNode; currentNode = nextNode; } return headNode; }