C ++ STL中的set :: lower_bound()函數

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<T> st; //declaration
st<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 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<int> 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 <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 lower_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<<"lower bound of 6 is "<<*(st.lower_bound(6));
return 0;
}

Output

輸出量

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

翻譯自: https://www.includehelp.com/stl/set-lower_bound-function-in-cpp-stl.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541230.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541230.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541230.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

flume入門

# example.conf: A single-node Flume configuration# Name the components on this agent #給那三個組件取個名字 a1.sources r1 a1.sinks k1 a1.channels c1# Describe/configure the source #類型, 從網絡端口接收數據,在本機啟動, 所以localhost, typespoolDir采集目錄源…

原生js設置div隱藏或者顯示_JavaScript動畫方式控制div元素的隱藏和顯示

jQuery實現此功能相對比較簡單&#xff0c;具體參閱點擊按鈕動畫方式隱藏和顯示div一章節。結合CSS3實現此功能也非常便利和適合&#xff0c;具體參閱JavaScript與CSS3動畫方式改變元素尺寸一章節。原生JavaScript實現稍顯麻煩&#xff0c;下面就通過代碼實例介紹一下如何實現此…

python線程任務run_Python線程類| 帶有示例的run()方法

python線程任務runPython Thread.run()方法 (Python Thread.run() Method) Thread.run() method is an inbuilt method of the Thread class of the threading module in Python. This method is used to represent a threads activity. It calls the method expressed as the …

哪個計算機無法做到雙屏顯示,怎么啟用雙屏顯示設置【圖文介紹】

隨著生活質量的提升&#xff0c;人們對于便利的要求越來越高&#xff0c;電腦的雙屏顯示成為現在用戶越來越關注的對象之一。比如炒股操作中&#xff0c;人們既要關注大盤的走動趨勢&#xff0c;又要關注特定股票的走勢&#xff0c;在普通的屏幕上就需要不斷地切換頁面&#xf…

1.django 開發環境搭建

2019獨角獸企業重金招聘Python工程師標準>>> 本教程使用的開發環境 本教程寫作時開發環境的系統平臺為 Windows 10 &#xff08;64 位&#xff09;&#xff0c;Python 版本為 3.5.2 &#xff08;64 位&#xff09;&#xff0c;Django 版本為 1.10.6。 建議盡可能地與…

改jpg_|我來改第04期|—人物海報設計

【我來改第04期】人物海報文案內容-Ad copyhttps://pan.baidu.com/s/16pz9_rcLXTGZ3xzKFjKN9g 密碼: r57t設計要求-Requirement尺寸&#xff1a;1080(高)*650(寬)像素&#xff0c;大小不大于5m設計要求&#xff1a;以目前的藍色為主要顏色(R:47,G:87,B:130)&#xff0c;畫面體…

Java即時類| plus()方法與示例

即時類plus()方法 (Instant Class plus() method) Syntax: 句法&#xff1a; public Instant plus(TemporalAmount t_amt);public Instant plus(long amt, TemporalUnit t_unit);plus() method is available in java.time package. plus()方法在java.time包中可用。 plus(Temp…

計算機領域中dns是什么意思,dns錯誤是什么意思?dns錯誤要如何解決?

隨著網絡的普及&#xff0c;電腦已經成為我們生活中必不可少的物品&#xff0c;它可以幫助我們工作和學習以及娛樂。不過電腦在使用的過程中&#xff0c;常常會出現一些問題&#xff0c;小編覺得最常見也最讓人心生煩躁的就是輸入網址打開之后出現網頁打不開&#xff0c;提示dn…

Launch Instruments

Launch Instruments 該儀器應用在Xcode應用程序&#xff0c;所以推出是在Xcode的最直接的方式。你也可以啟動它間接地通過碼頭&#xff0c;啟動&#xff0c;或命令行。The Instruments app lives inside the Xcode app, so the most direct way to launch it is from within Xc…

java clock計時_Java Clock類| offset()方法與示例

java clock計時Clock Class offset()方法 (Clock Class offset() method) offset() method is available in java.time package. offset()方法在java.time包中可用。 offset() method is used to generate a new Clock from the given base clock with added the given Duratio…

dataframe數據標準化處理_數據處理中的標準化、歸一化究竟是什么?

關注上方“Python數據科學”&#xff0c;選擇星標&#xff0c;精彩文章不會錯過&#xff01;今天說一個比較重要的內容&#xff0c;無論是在算法建模還是在數據分析都比較常見&#xff1a;數據歸一化和標準化。開始之前&#xff0c;請你先把網上看到的所有相關的博客、帖子都忘…

北航計算機學院博士機試考試題,北航2015考博真題回憶及全套資料 - 考博 - 小木蟲 - 學術 科研 互動社區...

我是2015年畢業的應屆碩士&#xff0c;報考了北航經管院的博士。想寫這篇文很久了&#xff0c;現在復試完等最后結果中&#xff0c;把自己一路走來的經驗分享給大家。1.報名報名之前很重要的一點就是聯系導師。我是研二下&#xff0c;快放暑假了才開始聯系導師。北航一般是11月…

用了Redis里面的map和set

map的操作用 hset&#xff0c;hget等 set的操作有 sadd sismember等 參考下面&#xff1a; http://blog.csdn.net/kwsy2008/article/details/48467441

java輸出不同顏色_Java設計模式-策略模式、狀態模式

推薦閱讀&#xff1a;一只Tom貓&#xff1a;都是“Redis惹的禍”&#xff0c;害我差點掛在美團三面&#xff0c;真是“虛驚一場”&#xff01;java喵&#xff1a;6大面試技能樹&#xff1a;JAVA基礎JVM算法數據庫計算機網絡操作系統前言當代碼中出現多重if-else語句或者switch語…

c++stl和std_std :: rotate()函數以及C ++ STL中的示例

cstl和stdC STL std :: rotate()函數 (C STL std::rotate() function) rotate() function is a library function of algorithm header, it is used to rotate left the elements of a sequence within a given range, it accepts the range (start, end) and a middle point,…

計算機硬盤正在工作應特別注意避免,初級計算機考試題庫

計算機的初級基本*作包括基本信息欄、計算機的基礎知識、五筆字型基礎、*互聯網的*作、常用辦公外設的使用、計算機硬件的日常維護與保養和office辦公工具的應用。下面是初級計算機考試題庫&#xff0c;請參考&#xff01;1.以下與信息有關的設備計算中&#xff0c;用于存儲信息…

abap 添加alv上的工具欄的按鈕_神器必會!“世界上最好的編輯器Source Insight”...

前言“Source Insight(以下簡稱SI)是世界上最好的編輯器”&#xff0c;說這句話不知道會不會出門被打呢&#xff1f;-_- 中國古話說得好&#xff0c;“文無第一&#xff0c;武無第二”&#xff0c;所以不敢說SI是最好的&#xff0c;但是說是“最好的之一”絕對是妥妥的。它以豐…

SLF4J with Logback in a Maven Project | Mograblog

SLF4J with Logback in a Maven Project | Mograblog

Ruby中帶有示例的Hash.key?(value)方法

Hash.key&#xff1f;(value)方法 (Hash.key?(value) Method) In this article, we will study about Hash.key?(value) Method. The working of the method cant be assumed because its quite a different name. Let us read its definition and understand its implementa…

計算機課傷害事故的防范,體育課安全傷害事故的防范與處理

摘 要&#xff1a;近年來&#xff0c;在教育改革的背景下&#xff0c;學校方面特別重視體育教學這一環節。做好體育教學工作&#xff0c;一方面能夠使學生達到強身健體的目的&#xff0c;另一方面能夠使學生的綜合素質水平得到有效提升。然而&#xff0c;在體育課中還會發生一些…