lower_bound () function uses Detailed

Brief introduction

lower_bound () function is used to find a container, a first address is greater than equal to find elements specific principle is binary search, so it can only be used for non-descending sequence .
He has three parameters, the first parameter is the initial address of the container, the second parameter is the end position of the container, the third parameter is the value of the element to be searched.
The return value is greater than the first element is equal to the address to be searched.

Specific use

   vector<int> v;
   v.push_back(1), v.push_back(2), v.push_back(3);
   //打印 2 的位置
   cout << lower_bound(v.begin(), v.end(), 2) - v.begin();
    int a[] = {1,2,3};
    //打印 2 的位置
    cout << lower_bound(a, a + 3, 2) - a;

Guess you like

Origin www.cnblogs.com/woxiaosade/p/11402748.html