日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/3/11 编程问答 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C ++ STL中的set :: lower_bound()函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

C ++ STL set :: lower_bound()函數(shù) (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()函數(shù)是預(yù)定義的函數(shù),用于獲取集合中任何元素的下限。

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的下限是指集合中第一個(gè)不被認(rèn)為在any_element之前的數(shù)字 。 因此,如果any_element本身存在,則它是any_element的下一個(gè)any_element 。

Prototype:

原型:

set<T> st; //declarationst<T> st::iterator it; //iterator declarationit=st.upper_bound(T key);

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

參數(shù): T鍵; // T是數(shù)據(jù)類型

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.

該函數(shù)從集合中找到任何所需元素的下限。 x的下限表示不考慮在x之前出現(xiàn)的集合中的第一個(gè)數(shù)字。 因此,如果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.lower_bound(6)Print *it; //6it=st.lower_bound(8)Print *it; //10

Header file to be included:

包含的頭文件:

#include <iostream>#include <set>OR#include <bits/stdc++.h>

C++ implementation:

C ++實(shí)現(xiàn):

#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 setcout<<"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

總結(jié)

以上是生活随笔為你收集整理的C ++ STL中的set :: lower_bound()函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。