-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbubblesort.java
More file actions
39 lines (39 loc) · 1003 Bytes
/
bubblesort.java
File metadata and controls
39 lines (39 loc) · 1003 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
30
31
32
33
34
35
36
37
38
39
import java.util.*;
class BinarySearch
{
public static int binarySearch(int array[],int l,int r,int search)
{
if(r>l)
{
int mid;
mid=(l+r)/2;
if(array[mid]==search)
return mid;
else if(array[mid]<key)
return binarySearch(array,mid+1,r,search);
else
return binarySearch(array,l,mid-1,search);
}
return -1;
}
/** Since it works by serching through the middle elemenet and process
according to whether the searching data is less or greater than it ,all this is
done above*/
public static void main(String [] args)
{
Scannner in=new Scanner(System.in);
System.out.println(“Enter the no. of element in array”);
int k=in.nextInt();
int array[]=new int[k];
System.out.println(“Enter the data”);
for(int i=0;i<k;i++)
array[i]=in.nextInt();
System.out.println(“Enter the data that you want to find”);
int search=in.nextInt();
int score=binarySearch(array,0,n-1,search)
if(score==-1)
System.out.println(“Element not found”);
else
System.out.println(“Element found at place”+score);
}
}