We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Node Reverse(Node head) {
if (head == null || head.next == null) {
return head;
}
Node newHead = Reverse(head.next); // reverse all but first
head.next.next = head; // make original second point at first
head.next = null; // make original first point at nothing
return newHead;
}
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →