sorry for the awkward question title. I don't really know how to explain without a code example. I have implemented a Linked List using generics, and I am trying to reverse it.
public Node<T> reverse() {
Node<T> prev = null;
while (head != null) {
Node<T> next = head.next;
head.next = prev;
prev = head;
head = next;
System.out.println("head: " + head.next + "\nprev: " + prev.next);
}
head = prev;
return prev;
}
head = prev;
My question is, why is this required?
My LinkedList outputs: [output]
But without the head = prev; line it simply outputs blank []. Is this something to do with generics?