class Node{ Node next = null; int data; public Node(int data){ this.data = data; } } class List{ Node rev(Node head) { Node temp = head; Node next = null, prev = null; while(temp != null) { next = temp.next; temp.next = prev; prev = temp; temp = next; } head = prev; return prev; } Node findMiddle(Node head,int length) { Node temp2 = head; int x = 0; while(temp2 != null && (x < length/2)) { temp2 = temp2.next; x++; } return temp2; } int length(Node head) { Node temp = head; int count = 0; while(temp != null) { temp = temp.next; count++; } return count; } void print(Node head) { Node temp = head; while(temp != null) { System.out.print(temp.data +" "); temp = temp.next; } System.out.println(); } boolean isPalindrome(Node head) { Node middle = findMiddle(head,length(head)); Node secondhead = middle.next; middle.next = null; Node rSecondhead = rev(secondhead); while(head != null && rSecondhead != null) { if(head.data == rSecondhead.data) { head = head.next; rSecondhead = rSecondhead.next; continue; } else return false; } return true; } public static void main(String[] args) { List l = new List(); //some test cases }