Search
 
SCRIPT & CODE EXAMPLE
 

CPP

binary search return index c++

int binarySearch(vector<int>& arr, int p, int r, int num) {
        while (p <= r) {
            int mid = (p + r)/2;
            
            if (arr[mid] == num) return mid;
            else if (arr[mid] > num) r = mid-1;
            else  p = mid+1;
        }
        return -1;
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: sum vector c++ 
Cpp :: error: ‘memset’ was not declared in this scope in cpp 
Cpp :: inserting at start in vector c++ 
Cpp :: erosion and dilation c++ 
Cpp :: uri online judge 1930 solution in c++ 
Cpp :: commets in codeblocks 
Cpp :: capture an entire line C++ 
Cpp :: can you verify adsense no ssl certificate 
Cpp :: ue4 find component c++ 
Cpp :: unknown type name pid_t 
Cpp :: replace character in a string c++ stack overflow 
Cpp :: c++ string to wstring 
Cpp :: qt qmessagebox 
Cpp :: c++ find index of an element 
Cpp :: random in range c++ 
Cpp :: priority queue c++ time complexity 
Cpp :: cpp infinity 
Cpp :: access first value in a set c++ 
Cpp :: how to print with the bool value in cpp 
Cpp :: function as argument in another function in c++ 
Cpp :: minimum and maximum value of a vector in C++ 
Cpp :: arduino notone 
Cpp :: how to get a letter from the user c++ string 
Cpp :: create random vectors c++ 
Cpp :: default access modifier in c++ 
Cpp :: c++ iterate over vector 
Cpp :: http.begin not working 
Cpp :: use lower bound in pair vector 
Cpp :: c++ nagetive to positive numbers 
Cpp :: c++ typeid 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =