C ++ STLでcrbegin()およびcrend()関数を設定します
この記事では、C++STLのset::crbegin()関数とset ::crend()関数、それらの構文、動作、および戻り値について説明します。
C ++ STLの設定とは何ですか?
C ++ STLのセットは、一般的な順序で一意の要素を持つ必要があるコンテナーです。要素の値は要素を識別するため、セットには一意の要素が必要です。セットコンテナに値を追加すると、後で変更することはできませんが、値を削除したり、セットに追加したりすることはできます。セットは二分探索木として使用されます。
set ::crbegin()とは何ですか?
crbegin()関数は、C ++ STLに組み込まれている関数であり、
構文
constant_iterator name_of_set.crbegin();
パラメータ
この関数はパラメータを受け入れません。
戻り値
この関数は、設定されたコンテナの最後の要素を指しているイテレータを返します。
例
Input: set<int> myset = {1, 2, 3, 4, 5};
myset.crbegin();
Output: 5 例
#include <bits/stdc++.h>
using namespace std;
int main(){
int arr[] = {1, 2, 3, 4, 5};
set<int> ch(arr, arr + 5);
for (auto i = ch.crbegin(); i!= ch.crend(); i++)
cout << *i << " ";
return 0;
} 出力
上記のコードを実行すると、次の出力が生成されます
5 4 3 2 1
設定内容::crend()
crend()関数は、C ++ STLに組み込まれている関数であり、
構文
constant_iterator name_of_set.crend();
パラメータ
この関数はパラメータを受け入れません。
戻り値
この関数は、関数に関連付けられているセットコンテナの最初の位置の直前の位置を指しているイテレータを返します。
例
Input: set<int> myset = {1, 2, 3, 4, 5};
myset.crend();
Output: 9 //random number before the first element in the set container. 例
#include <bits/stdc++.h>
using namespace std;
int main(){
int arr[] = {3, 5, 8, 1, 9};
set<int> ch(arr, arr + 5);
for(auto i = ch.crbegin(); i!= ch.crend(); i++)
cout << *i<< " ";
return 0;
} 出力
上記のコードを実行すると、次の出力が生成されます
9 8 5 3 1
-
C ++ STLでfind()関数を設定します
C ++STLのsetfind()関数は、setコンテナで検索される要素にイテレータを返します。要素が見つからない場合、イテレータはセット内の最後の要素の直後の位置を指します。 アルゴリズム Begin Define function printS() to print elements of set container. initialize an empty set container s. Insert some elements in s set container. Call function to pri
-
STLセットC++での挿入と削除
挿入 STLセットへの挿入は、insert()およびemplace()操作によって実行できます。 Insert() :Insert()は、要素をセットに挿入するために使用されます。挿入操作はオブジェクトへの参照を取ります。 使用される関数のリスト: st.size()=セットのサイズを返します。 st.insert()=要素をセットに挿入するために使用されます。 サンプルコード #include <iostream> #include <set> #include <string> #include <cstdlib> using