- Code: Select all
public static IntNode reverseLinks(IntNode head) {
if (head == null) {
return null;
} else if (head.next == null) {
return head;
} else {
IntNode temp = head;
IntNode newNode = null;
while (temp.next.next != null) {
temp = temp.next;
}
newNode = new IntNode(temp.next.data);
temp = null;
return new IntNode(newNode.data, reverseLinks(temp));
}
}
IntNode is a class with two constructors, one which takes in the value, and the other takes in the value along with the next node.

