Страницы: 1
Hello,
I'm having trouble reversing a linked list in Java. I'm trying to use the solution outlined in the following article:
I've written the following code, but it's not working correctly
public static LinkedListNode reverse(LinkedListNode head) {
LinkedListNode pre = null;
LinkedListNode curr = head;
while (curr != null) {
LinkedListNode next = curr.next;
curr.next = pre;
pre = curr;
curr = next;
}
return pre;
}
I'm not sure what I'm doing wrong, any help would be greatly appreciated! Thanks.
Отсутствует
Страницы: 1