Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int binarySearch(vector<int> arrayToSearch, int key, int L, int R) {
- int size = (int)arrayToSearch.size();
- int half = size / 2 - 1;
- if(key == arrayToSearch[half]) {
- return half;
- } else if(key > arrayToSearch[half]) {
- binarySearch(arrayToSearch, key, half+1, R);
- } else {
- binarySearch(arrayToSearch, key, L, half - 1);
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement