dimanche 9 février 2020

Lower_bound not working on the last element of a vector with 3 elements

vector<int> vec = {2,4,3};
vector<int>::iterator it;
it=lower_bound(vec.begin(),vec.end(),3);
cout<<*it;

This returns an output of 4 not 3 but

vector<int> vec = {2,3,4};
vector<int>::iterator it;
it=lower_bound(vec.begin(),vec.end(),3);
cout<<*it;

But this returns the correct output of 3. Please help me understand why it is failing in the corner case.

Aucun commentaire:

Enregistrer un commentaire