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::front() and vector::back() in C++ STL
- vector::empty() and vector::size() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::push_back() and vector::pop_back() in C++ STL
- vector::at() and vector::swap() in C++ STL
- vector::begin() and vector::end() in C++ STL
- Vector in C++ STL
- Modifiers for Vector in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- Sorting a vector in C++
- How does a vector work in C++?
- vector : : resize() in C++ STL
- vector :: assign() in C++ STL
- Using std::vector::reserve whenever possible