struct compare in the code contains two function which compares the key(searching element) with the first element in the vector
KEY ELEMENT 1 20 2 80 3 29 3 42 4 36 7 50 9 20 search for key 3 in vector Element found
The above binary_search operation has time complexity O(lg n)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- std::upper_bound and std::lower_bound for Vector in C++ STL
- Passing Reference to a Pointer in C++
- Nested list in C++ STL
- wcrtomb() function in C/C++
- vswprintf() function in C/C++
- wcstoul() function in C/C++
- wmemchr() function in C/C++
- wmemcmp() function in C/C++
- wcstod() function in C/C++
- wcscspn() function in C/C++