Java Array Divide divideAndConquer(int[] array, int num)

Here you can find the source of divideAndConquer(int[] array, int num)

Description

divide And Conquer

License

Open Source License

Declaration

public static int divideAndConquer(int[] array, int num) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int divideAndConquer(int[] array, int num) {
        return divideAndConquer(array, num, 0, array.length - 1);
    }/*from  w ww .j  a  va2 s.c o  m*/

    public static int divideAndConquer(int[] array, int num, int left,
            int right) {
        if (left > right)
            return -1;
        int middle = (right + left) / 2;
        if (array[middle] == num)
            return middle;
        if (array[middle] > num)
            return divideAndConquer(array, num, left, middle - 1);
        return divideAndConquer(array, num, middle + 1, right);
    }
}

Related

  1. divide(float[][] a, float num)
  2. divide(float[][][][] img, float val)
  3. divide(int[] array1, int[] array2)
  4. divide(long[] array, double value)
  5. divideAbsolute(double[] one, double[] two)
  6. divideArray(float[] array, float num)
  7. divideArray(T[] arr, Integer... cuts)
  8. divideArrayElements(final int[] array, final int divisor)
  9. divideBytearrays(byte[] ret, int headerLength, byte[] bArr)