-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchEle.java
More file actions
49 lines (45 loc) · 1.04 KB
/
SearchEle.java
File metadata and controls
49 lines (45 loc) · 1.04 KB
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
class Node3{
int data;
Node next;
Node3(int data1, Node next1){
data=data1;
next=next1;
}
Node3(int data1){
data=data1;
next=null;
}
}
public class SearchEle {
public static Node convertArr(int arr[]){
Node head=new Node(arr[0]);
Node mover=head;
for(int i=1;i<arr.length;i++){
Node temp=new Node(arr[i]);
mover.next=temp;
mover=temp;
}
return head;
}
public static boolean check(Node head,int k){
Node temp=head;
while(temp!=null){
if(temp.data==k){
return true;
}
temp=temp.next;
}
return false;
}
public static void main(String[] args) {
int arr[]={1,2,3,4,5};
int k=5;
Node head=convertArr(arr);
if(check(head,k)==true){
System.out.println("True");
}
else{
System.out.println("False");
}
}
}