@Test public void testSearchCirculation(){ Assert.assertEquals(Integer.valueOf(-2), BinarySearch.searchCirculation(array, -2)); Assert.assertEquals(Integer.valueOf(10), BinarySearch.searchCirculation(array, 10)); Assert.assertEquals(Integer.valueOf(0), BinarySearch.searchCirculation(array, 0)); Assert.assertEquals(null, BinarySearch.searchCirculation(array, 1)); }
public static Integer searchCirculation(int[] array, int value){ int low = 0; int high = array.length - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(value < array[middle]){ high = middle - 1; }else if(value > array[middle]){ low = middle + 1; }else{ return array[middle]; } } return null; }
BinarySearch { public static Integer searchCirculation(int[] array, int value){ int low = 0; int high = array.length - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(value < array[middle]){ high = middle - 1; }else if(value > array[middle]){ low = middle + 1; }else{ return array[middle]; } } return null; } }
BinarySearch { public static Integer searchCirculation(int[] array, int value){ int low = 0; int high = array.length - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(value < array[middle]){ high = middle - 1; }else if(value > array[middle]){ low = middle + 1; }else{ return array[middle]; } } return null; }  }
BinarySearch { public static Integer searchCirculation(int[] array, int value){ int low = 0; int high = array.length - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(value < array[middle]){ high = middle - 1; }else if(value > array[middle]){ low = middle + 1; }else{ return array[middle]; } } return null; }  static Integer searchCirculation(int[] array, int value); static Integer searchRecursive(int[] array, int value); }
BinarySearch { public static Integer searchCirculation(int[] array, int value){ int low = 0; int high = array.length - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(value < array[middle]){ high = middle - 1; }else if(value > array[middle]){ low = middle + 1; }else{ return array[middle]; } } return null; }  static Integer searchCirculation(int[] array, int value); static Integer searchRecursive(int[] array, int value);  }