Classic Binary Search
1 public class BinarySearch{ 2 public int BinarySearch(int[] array, int target){ 3 if(array == null || array.length = 0){ 4 return -1; 5 } 6 while (left < right){ 7 int mid = left + (right - left)/2; 8 if (array[mid] == target){ 9 return mid; 10 } else if (array[mid] > target) { 11 right = mid - 1; 12 } else { 13 left = mid + 1; 14 } 15 } 16 return -1; 17 } 18 }