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; }