Using class level (instance variable) while solving isPalindrome for singly LL

Hi there ,
i was solving a problem to find whether a given singly LL is palindrome or not .
after the solving the problem by reversing the linked list from middle , i came across the recursive solution for this , but in that approach they are using a Node type Class level variable
class LinkedList
{
Node head; // head of list
Node left;

boolean isPalindromeUtil(Node right)
{
left = head;

/* stop recursion when right becomes NULL */
if (right == null) 
    return true; 

/* If sub-list is not palindrome then no need to 
   check for current left and right, return false */
boolean isp = isPalindromeUtil(right.next); 
if (isp == false) 
    return false; 

/* Check values at current left and right */
boolean isp1 = (right.data == (left).data); 

/* Move left to next node */
left = left.next; 

return isp1; 

}
}

Here “head” variable is (class level), but as per my understanding using global variables are not recommended .
can you please provide a clear explanation for this .

Hi Rahul,
See in your approach if you don’t use global variable the value of left never change and left will always be pointing to the head of the linkedlist and the function will always return false no matter linkedlist is palindrome or not.

Hi Rahul
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.