Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions binarysearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class binarysearch {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr= {10,20,30,40,50};

int data=30;
System.out.println(binary(arr,data));
}
public static int binary(int[] arr,int data) {
int start=0;
int end=arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]==data)
{
return mid;
}
else if(arr[mid]<data){
start=mid+1;

}
else if(arr[mid]>data){
end=mid-1;
}

}
return -1;
}

}