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; //declaration
set<T> st::iterator it; //iterator declaration
it=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)
4
6
10
it=st.upper_bound(4)
Print *it; //6

Header 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 set
cout<<"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()函数相关推荐

  1. C语言bound函数,C/C++-STL中lower_bound与upper_bound的用法以及cmp函数

    ng-repeat里创建的自定义指令 在ng里,所有的指令在按照意愿正常工作之前的都需要编译一下,包含angularJS的自定义指令. ng模板里的所有指令都会在angularJS加载完毕之后编译一下 ...

  2. C++STL中vector容器 assign()函数的用法

    http://blog.sina.com.cn/s/blog_7b3a697301014aam.html assign函数: 函数原型: void assign(const_iterator firs ...

  3. 【C++】STL中vector的assign()函数用法

    参考: https://blog.csdn.net/qq_45893475/article/details/120250105 https://blog.csdn.net/doubleintfloat ...

  4. c语言中 push 函数,C ++ STL中的stack :: push()函数

    原型:stackst; //声明 st.push(T item); 参数:T item; //T是数据类型 返回类型: void 包含的头文件:#include #include OR #includ ...

  5. stl中map函数_map :: empty()函数以及C ++ STL中的Example

    stl中map函数 C ++ STL映射:: empty() (C++ STL map::empty()) It is built-in function in C++ STL and used to ...

  6. STL中的for_each()函数

    for_each()函数是C++ STL中的一个遍历函数,函数原型如下: for_each(InputIterator first, InputIterator last, Function func ...

  7. c语言asinh函数,C ++ STL中的asinh()函数

    该asinh()函数返回弧度的双曲正弦或反双曲正弦.它是C ++ STL中的内置函数. 该asinh()函数的语法如下.asinh(var) 从语法可以看出,该函数asinh()接受数据类型为floa ...

  8. c语言exp2是什么函数,C ++ STL中的exp2()函数

    在本文中,我们将讨论C ++ STL中用于复数的std::exp2()函数的工作,语法和示例. 什么是std::exp2()? 用于复数的std::exp2()函数是C ++ STL中的内置函数,该函 ...

  9. c语言tanh函数,C ++ STL中的tanh()函数

    该tanh()函数返回以弧度给出的角度的双曲正切值.它是C ++ STL中的内置函数. 该tanh()函数的语法如下.tanh(var) 从语法可以看出,该函数tanh()接受数据类型为float,d ...

最新文章

  1. 错误 error C2220: 警告被视为错误 - 没有生成“object”文件
  2. 微信小程序点击button按钮后重置输入框等表单内容
  3. java selenium click_按钮单击selenium java
  4. 【慢慢学Android】:2.SharedPreferences对数据的存储
  5. C#获取数据库中某个字段的最大值
  6. [转载]KL距离(相对熵)
  7. Android集成腾讯X5WebView
  8. 基于php的在线问卷调查系统
  9. python数字大小写转换代码_把金额小写转换成大写的Python代码
  10. Android SQLite Google 官方用法
  11. linux命令配置永久ip地址,Linux命令行永久修改IP地址、网关和DNS。
  12. 以太坊:分片Sharding FAQ
  13. 升级iOS 16后续航时间变短了,如何提升续航?
  14. 电脑我的世界服务器怎么按键显示,我的世界功能按键大全 操作按键全介绍
  15. python合并两个数据集_《利用Python进行数据分析》第7章 合并数据集
  16. c语言大作业打印课程表,课程表(c语言)
  17. 基础2-用卷积神经网络进行颅内和头皮脑电图数据分析的广义癫痫预测
  18. HDU 1427 速算24点 (深搜)
  19. 炫龙 shinelon笔记本电脑-毁灭者DD2如何U盘启动?
  20. OpenCV学习笔记(五十一)——imge stitching图像拼接stitching

热门文章

  1. python中改变参数值的方法_Python实现partial改变方法默认参数
  2. 计算机仿真在机械应用,浅谈计算机仿真在机械的应用.doc
  3. Android获取LAUNCHER,Android 获取Launcher 启动列表
  4. Ext grid 根据行号获取行数据
  5. vue获取DOM元素并设置属性
  6. 三年前端,面试思考(二)
  7. html中常见的小问题(1)
  8. http://www.tldp.org/LDP/abs/abs-guide.txt.gz
  9. scrapy 采集网页出现丢失url的问题
  10. Day 9 函数的初识1