Skip to content

Instantly share code, notes, and snippets.

@Dimanaux
Last active January 13, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimanaux/5cebddce31ccd913d63a78d14c78faea to your computer and use it in GitHub Desktop.
Save Dimanaux/5cebddce31ccd913d63a78d14c78faea to your computer and use it in GitHub Desktop.
public class BinarySearchDemoClass {
public static int binarySearch(String[] array, String value) {
int l = 0, r = array.length;
int mid = (l + r) / 2;
while (l < r) {
if (value.compareTo(array[mid]) == 0) {
return mid;
} else if (value.compareTo(array[mid]) > 0) {
l = mid;
} else {
r = mid;
}
mid = (l + r) / 2;
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment