SHARE
TWEET

Untitled

a guest Jun 17th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class BinSearch {
  2.  
  3. public int search(int search, int[] array) {
  4.  
  5.           return recursivSearch(array, 0, array.length-1, search);
  6. }
  7.  
  8.  
  9. private int recursivSearch(int[] array, int start, int end, int search) {
  10.  
  11.    
  12.    
  13.       if (end<start) {
  14.           return -1;
  15.       }
  16.       int middle = (start + end) / 2;  
  17.         if (search < array[middle]) {
  18.           return recursivSearch(array, start, middle-1, search);
  19.         }
  20.         else if (search > array[middle]) {
  21.           start = middle + 1;
  22.           return recursivSearch(array, middle+1, end, search);
  23.         }
  24.         else {
  25.           System.out.println(middle);
  26.           return middle;
  27.        }  
  28. }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top