C ++ STL中的set :: upper_bound()函数
C ++ STL set :: upper_bound()函數 (C++ STL set::upper_bound() function)
set::upper_bound() function is a predefined function, it is used to get the upper bound of any element in a set.
set :: upper_bound()函數是預定義的函數,用于獲取集合中任何元素的上限。
it finds upper bound of any desired element from the set. Upper bound of any_element means the first number in the set that's immediate next to any_element.
它從集合中找到任何所需元素的上限。 上界any_element手段的第一個號碼的組的直接旁邊any_element。
Prototype:
原型:
set<T> st; //declarationset<T> st::iterator it; //iterator declarationit=st.upper_bound(T key);Parameter: T key; //T is the data type
參數: T鍵; // T是數據類型
Return type: If upper_bound of the key exists in the set iterator pointer to the upper bound, Else, st.end()
返回類型:如果鍵的upper_bound存在于指向頂部上限的設置迭代器指針中,否則為st.end()
Usage:
用法:
The function finds upper bound of any desired element from the set. Upper bound of x is immediate next of x.
該函數從集合中找到任何所需元素的上限。 x的上限緊鄰x。
Example:
例:
For a set of integer,set<int> st;st.insert(6);st.insert(4);st.insert(10);set content: //sorted always(ordered)4610it=st.upper_bound(4)Print *it; //6Header file to be included:
包含的頭文件:
#include <iostream>#include <set>OR#include <bits/stdc++.h>C++ implementation:
C ++實現:
#include <bits/stdc++.h> using namespace std;void printSet(set<int> st){set<int>:: iterator it;cout<<"Set contents are:\n";if(st.empty()){cout<<"empty set\n";return;}for(it=st.begin();it!=st.end();it++)cout<<*it<<" ";cout<<endl; }int main(){cout<<"Example of upper_bound function\n";set<int> st;set<int>:: iterator it;cout<<"inserting 4\n";st.emplace(4);cout<<"inserting 6\n";st.emplace(6);cout<<"inserting 10\n";st.emplace(10);printSet(st); //printing current setcout<<"upper bound of 6 is "<<*(st.upper_bound(6));return 0; }Output
輸出量
Example of upper_bound function inserting 4 inserting 6 inserting 10 Set contents are: 4 6 10 upper bound of 6 is 10翻譯自: https://www.includehelp.com/stl/set-upper_bound-function-in-cpp-stl.aspx
總結
以上是生活随笔為你收集整理的C ++ STL中的set :: upper_bound()函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 宽带费多少钱啊?
- 下一篇: Python字符串| join()方法与