189 8069 5689

multisetupper-创新互联

multiset::upper_bound()是C++ STL中的内置函数,该函数返回一个迭代器,该迭代器指向刚好大于key的下一个元素。如果参数中传入的键超过了容器中的大键,则返回的迭代器将指向一个元素,确切的说解引用后是一个index或者pos值,该数值对应容器中最后一个元素之后的位置。

创新互联客户idc服务中心,提供服务器托管、成都服务器、成都主机托管、成都双线服务器等业务的一站式服务。通过各地的服务中心,我们向成都用户提供优质廉价的产品以及开放、透明、稳定、高性价比的服务,资深网络工程师在机房提供7*24小时标准级技术保障。
* A built-in function in C++ STL that returns an iterator pointing to the immediate next element which is just greater than k.
** If the key passed in the parameter exceeds the maximum key in the container, then the iterator returned points an element which points to the position after the last element in the container
multiset_name.upper_bound(key)
#include#includeusing namespace std; 
int main() 
{ 
  
    multisets; 
  
    // Function to insert elements 
    // in the multiset container 
    s.insert(1); 
    s.insert(3); 
    s.insert(3); 
    s.insert(5); 
    s.insert(4); 
    s.insert(8);
  
    cout<< "The multiset elements are:"; 
    for (auto it = s.begin(); it != s.end(); it++) 
        cout<< *it<< " "; 
  
    // when 3 is present 
    auto it = s.upper_bound(3); 
    cout<< "\nThe upper bound of key 3 is "; 
    cout<< (*it)<< endl; 
  
    // when 2 is not present 
    // points to next greater after 2 
    it = s.upper_bound(2); 
    cout<< "The upper bound of key 2 is "; 
    cout<< (*it)<< endl; 

    // when 8 equal the max element in multiset 
    it = s.upper_bound(8); 
    cout<< "The upper bound of key 8 is "; 
    cout<< (*it)<< endl; // result is equivalent to exceeds the max element in multiset. 
  
    // when 10 exceeds the max element in multiset 
    it = s.upper_bound(10); 
    cout<< "The upper bound of key 10 is "; 
    cout<< (*it)<< endl; // get a index  which is just greater than max element in multiset
    // the max element in multiset is 8, which index is 5, so we get a new position is 6.
  
    return 0; 
}

Output:

The multiset elements are:1 3 3 4 5 8
The upper bound of key 3 is 4
The upper bound of key 2 is 3
The upper bound of key 8 is 6
The upper bound of key 10 is 6

multiset::lower_bound()是C++ STL中的内置函数,该函数返回一个迭代器,该迭代器指向刚好等于key的一个元素。如果参数中传递的键不在容器中,则返回的迭代器将指向刚好大于key的那个元素,如果传入的key超过了容器中的大键,则返回的迭代器将指向一个元素确切的说解引用后是一个index或者pos值,该数值对应容器中最前面一个元素之后的位置。

* A built-in function in C++ STL which returns an iterator pointing to the first element in the container which is equivalent to k passed in the parameter.
** In case k is not present in the set container, the function returns an iterator pointing to the immediate next element which is just greater than k.
*** If the key passed in the parameter exceeds the maximum value in the container, then the iterator returned point the number of elements in the container
multiset_name.lower_bound(key)
#include#includeusing namespace std;

int main()
{
  
    multisets;
  
    // Function to insert elements
    // in the multiset container
    s.insert(2);
    s.insert(3);
    s.insert(3);
    s.insert(2);
    s.insert(6);
  
    cout<< "The multiset elements are: ";
    for (auto it = s.begin(); it != s.end(); it++)
        cout<< *it<< " "; // order by key automaticly, from little to bigger
  
    // when 3 is present
    auto it = s.lower_bound(3);
    cout<< "\nThe lower bound of key 3 is ";
    cout<< (*it)<< endl;

    // when 0 is not present
    // points to next element just greater after 0
    it = s.lower_bound(0);
    cout<< "The lower bound of key 0 is ";
    cout<< (*it)<< endl;
  
    // when 5 is not present
    // points to next element just greater after 5
    it = s.lower_bound(5);
    cout<< "The lower bound of key 5 is ";
    cout<< (*it)<< endl;
  
    // when 8 exceeds the max element in multiset
    it = s.lower_bound(8);
    cout<< "The lower bound of key 8 is ";
    cout<< (*it)<< endl; // get a index or pos which is just greater than the max element in multiset
    // the max element in multisetis 6, which pos is 4, so we get a new position is 5.
    return 0;
}

Output:

The multiset elements are: 2 2 3 3 6
The lower bound of key 3 is 3
The lower bound of key 0 is 2
The lower bound of key 5 is 6
The lower bound of key 8 is 5

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


新闻标题:multisetupper-创新互联
分享URL:http://cdxtjz.cn/article/dpishd.html

其他资讯