Java Binary Search binarySearch(double values[], double search)

Here you can find the source of binarySearch(double values[], double search)

Description

binary Search

License

Apache License

Declaration

public static int binarySearch(double values[], double search) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int binarySearch(double values[], double search) {
        int min = 0, max = values.length;
        int index = max / 2;

        while (max - min > 1) {
            if (values[index] == search) {
                return index;
            }/*  w w  w .j a v  a  2  s.c o  m*/
            if (values[index] < search) {
                min = index;
            } else {
                max = index;
            }
            index = (max + min) / 2;
        }
        if (values[index] < search) {
            index++;
        }
        return index;
    }
}

Related

  1. binarySearch(byte[] a, byte key, int startPos)
  2. binarySearch(byte[] a, int key)
  3. binarySearch(byte[] readBuffer, int offset, int length, byte value)
  4. binarySearch(char[] arr, int key)
  5. binarySearch(double experience, int min, int max)
  6. binarySearch(double[] a, double key)
  7. binarySearch(double[] arr, double value, int p, int q)
  8. binarySearch(final double[] array, final double val)
  9. binarySearch(final Enum[] full, final int[] partial, final char key, final int index)