Hello all,
I'm trying to reverse a linked list in Java and am having some difficulty. I'm following the instructions in this post, but I'm getting an error when I run my code.
I'm including my code below. Any help would be greatly appreciated.
Thanks in advance!
public static ListNode reverseList(ListNode head)
{
ListNode prev = null;
ListNode curr = head;
ListNode next = null;
while (curr != null) {
next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
head = prev;
return head;
}