For an Increasing/Ascending array, I grasped the notion of Lower and Upper discovered.
Lower Bound: iterator pointing to the first element in the [first, last] range >= Value
Upper Bound: iterator pointing to the first element in the [first, last] range > Value
Below is my Decreasing/Non-ascending vector code, which is causing me problems:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<int> vec = {45,40,35,12,6,3};
auto itr3 = lower_bound(vec.begin(),vec.end(),40);
auto itr4 = upper_bound(vec.begin(),vec.end(),40);
if(itr3 == vec.end() && itr4 == vec.end())
cout<<"Lower & Upper Bound not Found\n";
else
{
cout <<"lower Bound of 40 :"<<*itr3<<endl;
cout <<"Upper Bound of 40 :"<<*itr4<<endl;
}
return 0;
}
The Output is:
Lower & Upper Bound not Found.
But as mentioned above the output should be something like :
lower Bound of 40 :40
Upper Bound of 40 :45
Please assist me in understanding the lower and upper bound behaviour in the situation of decreasing/non-ascending vectors.