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 { constructor ( ) { this . data = 0 ; this . prev = null ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; new_node . prev = null ; if ( head_ref != null ) head_ref . prev = new_node ; head_ref = new_node ; return head_ref ; } function isPalindrome ( left ) { if ( left == null ) return true ; var right = left ; while ( right . next != null ) right = right . next ; while ( left != right ) { if ( left . data != right . data ) return false ; left = left . next ; right = right . prev ; } return true ; } var head = null ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; if ( isPalindrome ( head ) ) document . write ( " " ) ; else document . write ( " " ) ;