Referring to my previous post, should I consider using current
pointers for this code snippet for reversing a linked list using recursion?
public static List ReverseRecursion(List head){
List newHead;
List current = head;
if(current == null){
return null;
}
if(current.next == null){
head = current;
return head;
}
newHead = ReverseRecursion(current.next);
current.next.next = current;
current.next = null;
return newHead;
}
Or should I consider the solution without using current
node as someone pointed out in their solution like this?
public static List ReverseRecursion(List head){
List newHead;
if(head == null){
return null;
}
if(head.next == null){
return head;
}
newHead = ReverseRecursion(head.next);
head.next.next = head;
head.next = null;
return newHead;
}