binary_search(), upper_bound(), lower_bound() binary search

vector a = {0,1,2,2,3,4}; The premise is that a is already in ascending order

cout << binary_search(a.begin(), a.end(), 3);
// find if 3 exists, return false or true

auto it = upper_bound(a.begin(), a.end(), 2);// Return the address of the first number greater than 2 from left to right

auto itt = lower_bound(a.begin(), a.end(), 2);// Return the address of the first number greater than or equal to 2 from left to right

// return to a.end() if not found

Guess you like

Origin blog.csdn.net/qq_45812180/article/details/114495535