Untitled
unknown
plain_text
2 years ago
502 B
5
Indexable
public class BinarySearch { public static void binarySearch(int arr[],int start,int end,int key) { int mid=(start+end)/2; while(start<=end) { if(arr[mid]<key) { start=mid+1; } else if(arr[mid]==key) { System.out.println("element is found at index:"+mid); break; } else { end=mid-1; } mid=(start+end)/2; } if(start>end) { System.out.println("lement is not found"); } } public static void main(string[]args) { int arr[]={10,20,30,40,50); int key=30; int end=arr.length-1; binarySearch(arr,0,end,key); } }
Editor is loading...
Leave a Comment