博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C ++ STL中的set :: lower_bound()函数
阅读量:2532 次
发布时间:2019-05-11

本文共 2298 字,大约阅读时间需要 7 分钟。

C ++ STL set :: lower_bound()函数 (C++ STL set::lower_bound() function)

set::lower_bound() function is a predefined function, it is used to get the lower bound of any element in a set.

set :: lower_bound()函数是预定义的函数,用于获取集合中任何元素的下限。

it finds lower bound of any desired element from the set. Lower bound of any_element means the first number in the set that's not considered to go before any_element. So, if any_element is itself present, then it's any_element else immediate next of any_element.

它从集合中找到任何所需元素的下限。 any_element的下限是指集合中第一个不被认为在any_element之前的数字 。 因此,如果any_element本身存在,则它是any_element的下一个any_element 。

Prototype:

原型:

set
st; //declaration st
st::iterator it; //iterator declaration it=st.upper_bound(T key);

Parameter: T key; //T is the data type

参数: T键; // T是数据类型

Return type: If lower_bound of the key exists in the set, Iterator pointer to the lower bound, Else, st.end()

返回类型:如果键的lower_bound存在于集合中,则迭代器指针指向下限,否则为st.end()

Usage:

用法:

The function finds lower bound of any desired element from the set. Lower bound of x means the first number in the set that's not considered to go before x. So, if x is itself present, then it's x else immediate next of x.

该函数从集合中找到任何所需元素的下限。 x的下限表示不考虑在x之前出现的集合中的第一个数字。 因此,如果x本身存在,则x紧接x 。

Example:

例:

For a set of integer,    set
st; st.insert(6); st.insert(4); st.insert(10); set content: //sorted always(ordered) 4 6 10 it=st.lower_bound(6) Print *it; //6 it=st.lower_bound(8) Print *it; //10

Header file to be included:

包含的头文件:

#include 
#include
OR #include

C++ implementation:

C ++实现:

#include 
using namespace std;void printSet(set
st){
set
:: 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<
st; set
:: 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<<"lower bound of 6 is "<<*(st.lower_bound(6)); return 0;}

Output

输出量

Example of lower_bound functioninserting 4inserting 6inserting 10Set contents are:4 6 10lower bound of 6 is 6

翻译自:

转载地址:http://txtzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_02 微服务核心基础讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-01 什么是微服务的注册中心
查看>>