Datasets:

ArXiv:
License:
File size: 1,161 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 class PalindromeList{
     static class Node
     {
         int data;
         Node next;
         static Node newNode(int data)
         {
             Node temp = new Node();
             temp.data = data;
             temp.next = null;
             return temp;
         }
     };

     // Create new Node
    public static void main(String args[]){
        Node list=new Node().newNode(1);
        list.next=new Node().newNode(2);
        list.next.next=new Node().newNode(1);
        boolean check=isPalindrome(list);
        if(check==true)
            System.out.println("It is Palindrome");
        else
            System.out.println("It is not a Palindrome");
    }
    static Node left = null;
    public static boolean isPalindrome(Node head) {
        left = head;
        check(head);
        return value;
    }
    static boolean value = true;
    static void check(Node right){
        if(right == null){
            return;
        }

        check(right.next);

        if(right.data != left.data){
            value = false;
            return;
        }
        left = left.next;
    }
 }