Lower_bound
int myints[] = {10,20,30,30,20,10,10,20};
std::vector v(myints,myints+8); // 10 20 30 30 20 10 10 20
std::sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30
std::cout << std::endl;
for (std::vector::iterator it = v.begin(); it != v.end(); it++)
{
std::cout << " " << *it << " ";
}
std::cout << std::endl;
std::vector::iterator low,up;
low=std::lower_bound (v.begin(), v.end(), 10); // ^
up= std::upper_bound (v.begin(), v.end(), 10); // ^
int myints[] = {10,20,30,30,20,10,10,20};
std::vector
std::sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30
std::cout << std::endl;
for (std::vector
{
std::cout << " " << *it << " ";
}
std::cout << std::endl;
std::vector
low=std::lower_bound (v.begin(), v.end(), 10); // ^
up= std::upper_bound (v.begin(), v.end(), 10); // ^
找出 指定數值的位置 排序後
位置 0 -> 10 lower_bound = 0
位置 3 -> 20 但是前一個是10 所以 upper_bound = 3