Created
June 21, 2014 02:11
-
-
Save yao2030/205f3133e12f1d4e7f71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int BinarySearch(int a[], int size, int p) { | |
int L = 0; | |
int R = size - 1; | |
while (L <= R) { | |
int mid = (L + R) / 2; | |
if (p == a[mid]) { | |
return mid; | |
} else if (p > a[mid]) { | |
L = mid + 1; | |
} else { | |
R = mid - 1; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment