10 30 40 40 40 50 60
0 1 2 3 4 5 6 7
upper_bound(a,a+n,40)
why it not pointing to location 2 in video it shows 5
plz tell the condition of upper_bound and lower_bound
which include equality condition
Upper_bound lower_bound
@dakshi
lower_bound returns an iterator pointing to the first element in the array which has a value not less than ‘searched val’.(means it gives index of value greater than or equal to searched value)
upper_bound returns an iterator pointing to the first element in the array which has a value greater than ‘searched val’.
so here first element which is not less than 40 is 40 and index of that is 2 so your lower_bound is returning 2 as answer for this
and first element which is greater than 40 is 50 and index of that is 5 so your upper_bound is returning 5 as answer