zoukankan      html  css  js  c++  java
  • lower_bound 和 upper_bound

    Return iterator to lower bound

    Returns an iterator pointing to the first element in the range [first,last) which does not compare less than val.

    Return iterator to upper bound

    Returns an iterator pointing to the first element in the range [first,last) which compares greater than val.

    // lower_bound/upper_bound example
    #include <iostream>     // std::cout
    #include <algorithm>    // std::lower_bound, std::upper_bound, std::sort
    #include <vector>       // std::vector
    
    int main () {
      int myints[] = {10,20,30,30,20,10,10,20};
      std::vector<int> 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::vector<int>::iterator low,up;
      low=std::lower_bound (v.begin(), v.end(), 20); //          ^
      up= std::upper_bound (v.begin(), v.end(), 20); //                   ^
    
      std::cout << "lower_bound at position " << (low- v.begin()) << '
    ';
      std::cout << "upper_bound at position " << (up - v.begin()) << '
    ';
    
      return 0;
    }

    Output:

    lower_bound at position 3
    upper_bound at position 6
     
  • 相关阅读:
    linux 常用命令
    ubuntu 安装在硬盘与配置
    linux管道符、重定向与环境变量
    linux用户身份与文件权限
    centos开启ftp服务
    js实现常见排序算法
    算法分析
    Vim
    CSS的3种使用方法
    cookie 在登录时的存储,获取,清除
  • 原文地址:https://www.cnblogs.com/gongpixin/p/5490984.html
Copyright © 2011-2022 走看看