-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpll.java
79 lines (51 loc) · 1.3 KB
/
pll.java
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.*;
class Linkedlist<T>{
Node head = null;
class Node{
T data;
Node next;
Node(T ch){
data = ch;
next = null;
}
}
void insert(T d){
Node new_node = new Node(d);
if(head == null)
head = new_node;
else{
Node temp = head;
while(temp.next!=null) temp = temp.next;
temp.next = new_node;
}
}
void display(){
Node temp = head;
while(temp!= null){
System.out.print(temp.data+" ");
temp = temp.next;
}
}
boolean c_pl(Node a, Node b){
if(b == null) return true;
boolean ans = c_pl(a, b.next);
if(ans == false) return false;
if(a.data != b.data) return false;
a = a.next;
return true;
}
}
public class pll {
public static void main(String[] args){
Linkedlist<Character> ll = new Linkedlist<Character>();
ll.insert('m');
ll.insert('a');
ll.insert('a');
ll.insert('a');
ll.insert('m');
ll.display();
Linkedlist.Node first = ll.head;
Linkedlist.Node last = ll.head;
System.out.println(ll.c_pl(first, last));
}
}