Created
July 5, 2013 21:25
-
-
Save cocodrips/5937356 to your computer and use it in GitHub Desktop.
二分探索 再帰ver
This file contains hidden or 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 binarySearchRecursive(int[] array, int x, int low, int high){ | |
if(low > high) return -1; | |
int mid = (low + high) / 2; | |
if (array[mid] < x) { | |
return binarySearchRecursive(array, x, mid + 1, high); | |
}else if(array[mid] > x){ | |
return binarySearchRecursive(array, x, low, mid - 1); | |
}else{ | |
return mid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment