-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCautare binara.java
More file actions
29 lines (29 loc) · 999 Bytes
/
Cautare binara.java
File metadata and controls
29 lines (29 loc) · 999 Bytes
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
import java.util.*;
public class Eccpr{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer>list = new ArrayList<>();
for(int i=0;i<n;i++){
list.add(sc.nextInt());
}
int find = sc.nextInt();
Collections.sort(list);
while(list.size()>0){
if(list.size()==1){
System.out.println(list.get(0));
System.exit(0);
}
if(list.get(list.size()/2)>find){
System.out.println(list.get(list.size()/2));
list.subList(list.size()/2,list.size()).clear();
}else if(list.get(list.size()/2)<find){
System.out.println(list.get(list.size()/2));
list.subList(0, list.size()/2).clear();
}else{
System.out.println(find);
System.exit(0);
}
}
}
}