The lower_bound() and upper_bound() functions by default work on non decreasing array. The lower_bound() function finds iterator of first element that does not compare less to given element. The upper_bound() function returns iterator to first element that is greater.
Given an array converting this to an non increasing vector, applying the std:: upper_bound and std:: lower_bound function to the vector
For array sorted in non-increasing array, lowe_bound() finds iterator to first element that does not compare greater than to given element. upper_bound() finds iterator to first element that is smaller than given element. We use grater() for this purpose.
lower_bound at position 5 upper_bound at position 4
- vector :: cbegin() and vector :: cend() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::empty() and vector::size() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::front() and vector::back() in C++ STL
- vector::begin() and vector::end() in C++ STL
- vector::at() and vector::swap() in C++ STL
- Vector in C++ STL
- vector :: assign() in C++ STL
- vector : : resize() in C++ STL
- Sorting a vector in C++
- How does a vector work in C++?
- vector::operator= and vector::operator[ ] in C++ STL
- Using std::vector::reserve whenever possible
- vector::emplace_back in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.