reversePointerRecursively is not working.
Recursive Reverse a Linked List
the problem in your code is that the tail pointer is not updated appropriately while inserting elements in linked list.
I updated the tail pointer in reversePointerRecursivelyHelper() function for temporary fix.
public void reversePointerRecursively() {
reversePointerRecursivelyHelper(head);
Node temp = head;
head=tail;
tail=temp;
tail.next=null;
}
public void reversePointerRecursivelyHelper(Node n){
if(n.next==null){
tail = n;
return;
}
reversePointerRecursivelyHelper(n.next);
n.next.next=n;
}
this code will work fine.
But ideally tail pointer should be updated in addLast() function. I am leaving that to you. try to fix it.
thanks
please rate and resolve if satisfied.
solution: update tail pointer when you add some element in the last.
I
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.