CBredlow

Binary search using integers

Oct 26th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. public static int binarySearch(int [] array, int answer, int start, int end)
  2. {
  3. int current = array[(start+end)/2];
  4. if(current==answer)
  5. {
  6. return current;
  7. }else{
  8. if(current<answer)
  9. {
  10. return binarySearch(array, answer, current, end);
  11. }else{
  12. return binarySearch(array, answer, start, current);
  13. }
  14. }
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment