Java Binary Search binarySearch(char[] arr, int key)

Here you can find the source of binarySearch(char[] arr, int key)

Description

binary Search

License

Open Source License

Declaration

static int binarySearch(char[] arr, int key) 

Method Source Code

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

public class Main {
    static int binarySearch(char[] arr, int key) {
        int length = arr.length;
        if (key <= arr[length - 1]) {
            int l = 0;
            int r = length - 1;
            while (l <= r) {
                int mid = (l + r) >>> 1;
                char val = arr[mid];
                if (key > val) {
                    l = mid + 1;/*from ww w .  j  a  va  2s  .  co m*/
                } else if (key < val) {
                    r = mid - 1;
                } else {
                    return mid;
                }
            }
        }
        return 0xffff;
    }
}

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(double experience, int min, int max)
  5. binarySearch(double values[], double search)
  6. binarySearch(double[] a, double key)
  7. binarySearch(double[] arr, double value, int p, int q)