-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursive_Binary_Search.java
More file actions
77 lines (57 loc) · 1.36 KB
/
Recursive_Binary_Search.java
File metadata and controls
77 lines (57 loc) · 1.36 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
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
public class Recursive_Binary_Search
{
static int prodt=1;
static int rev=0;
static int Binary_Search(int start, int end, int[] A, int t){
int mid = (start + end)/2;
if(start > end){
// System.out.print("Not Found");
return -1;
}
if( A[mid]==t){
System.out.print(mid+1);
}
if(A[mid] < t){
return Binary_Search(mid+1, end, A, t);
}
if(A[mid] > t){
return Binary_Search(start, mid, A, t);
}
return 0;
}
static void Print(int n){
if(n<1)
return;
else{
Print(n-1);
System.out.print(" "+n);
}
}
static int product(int n){
if(n==0){
return 1;
}
return n%10 * product(n/10);
}
static void rev_Number(int n){
if(n==0){
return;
}
int dig;
dig = n%10;
rev = rev*10 + dig;
rev_Number(n/10);
}
public static void main(String[] args) {
int[] a = new int[5];
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 5;
Binary_Search(0, a.length - 1, a, 1);
// Print(5);
// int d= product(123456);
// System.out.print(c);
}
}