Answers for "binary search arraylist algorithm"

0

binary search arraylist algorithm

public static int binarySearch(int[] elements, int target) {
      int left = 0;
      int right = elements.length - 1;
      while (left <= right)
      {
         int middle = (left + right) / 2;
         if (target < elements[middle])
         {
            right = middle - 1;
         }
         else if (target > elements[middle])
         {
            left = middle + 1;
         }
         else {
            return middle;
         }
       }
       return -1;
   }
Posted by: Guest on November-29-2020

Code answers related to "binary search arraylist algorithm"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language