Check if a doubly linked list of characters is palindrome or not | Structure of node ; Given a reference ( pointer to pointer ) to the head of a list and an int , inserts a new node on the front of the list . ; Function to check if list is palindrome or not ; Find rightmost node ; Driver program
class Node : NEW_LINE INDENT def __init__ ( self , data , next , prev ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = next NEW_LINE self . prev = prev NEW_LINE DEDENT DEDENT def push ( head_ref , new_data ) : NEW_LINE INDENT new_node = Node ( new_data , head_ref , None ) NEW_LINE if head_ref != None : NEW_LINE INDENT head_ref . prev = new_node NEW_LINE head_ref = new_node NEW_LINE DEDENT return head_ref NEW_LINE DEDENT def isPalindrome ( left ) : NEW_LINE INDENT if left == None : NEW_LINE INDENT return True NEW_LINE DEDENT right = left NEW_LINE while right . next != None : NEW_LINE INDENT right = right . next NEW_LINE DEDENT while left != right : NEW_LINE INDENT if left . data != right . data : NEW_LINE INDENT return False NEW_LINE DEDENT left = left . next NEW_LINE right = right . prev NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT head = None NEW_LINE head = push ( head , ' l ' ) NEW_LINE head = push ( head , ' e ' ) NEW_LINE head = push ( head , ' v ' ) NEW_LINE head = push ( head , ' e ' ) NEW_LINE head = push ( head , ' l ' ) NEW_LINE if isPalindrome ( head ) : NEW_LINE INDENT print ( " It ▁ is ▁ Palindrome " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Palindrome " ) NEW_LINE DEDENT DEDENT