例を使用したC++STLのmultisetlower_bound()
このチュートリアルでは、C ++ STLのマルチセットlower_bound()を理解するためのプログラムについて説明します。
関数lower_bound()は、指定されたパラメーターと同等のコンテナー内の要素の最初の存在を返します。それ以外の場合は、それよりもすぐに大きい要素を返します。
例
#include <bits/stdc++.h>
using namespace std;
int main(){
multiset<int> s;
s.insert(1);
s.insert(2);
s.insert(2);
s.insert(1);
s.insert(4);
cout << "The multiset elements are: ";
for (auto it = s.begin(); it != s.end(); it++)
cout << *it << " ";
auto it = s.lower_bound(2);
cout << "\nThe lower bound of key 2 is ";
cout << (*it) << endl;
it = s.lower_bound(3);
cout << "The lower bound of key 3 is ";
cout << (*it) << endl;
it = s.lower_bound(7);
cout << "The lower bound of key 7 is ";
cout << (*it) << endl;
return 0;
} 出力
The multiset elements are: 1 1 2 2 4 The lower bound of key 2 is 2 The lower bound of key 3 is 4 The lower bound of key 7 is 5
-
STLにマルチセットを実装するC++プログラム
マルチセットは、複数の要素が同じ値を持つことができる連想コンテナの一種です。 機能と説明: Functions are used here: ms.size() = Returns the size of multiset. ms.insert) = It is used to insert elements to the multiset. ms.erase() = Removes the value from the multiset. ms.find() = Returns an it
-
STLにリストを実装するC++プログラム
リストは、連続しないメモリ割り当てを可能にするシーケンスコンテナです。リストはベクトルに比べてトラバースが遅くなりますが、位置が見つかると、挿入と削除がすばやく行われます。 機能と説明: From main(), we have called following functions: fl.resize() = Returns the resize of list. fl.push_front() = It is used to push elements into a list from the front. fl