#include
#include
using namespace std;
int main()
{
int arr[5] = { 4, 5, 1, 0, 1 };
sort( arr, arr+5 );
cout<< lower_bound( arr, arr+5, 3 ) - arr <<endl;
return 0;
}
What will be the output? please explain in detail.
Lower_bound in c++ doubt in c++ stl quiz
Since 15 is not present so it should return the end iterator? the end iterator will be 6 or 7?{ sets; s.insert(1);s.insert(5);s.insert(7); s.insert(2);s.insert(12);s.insert(10); // so the final set is 1,5,7,2,12,10?? auto it = s.lower_bound(15); cout<< *it; Please explain the output for this as well.
The output is 2 . After sorting, arr
becomes {0, 1, 1, 4, 5}
. lower_bound
returns the first position where 3
can be inserted while maintaining order, which is index 2.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.