C ++ STLでupper_bound()関数を設定します
この記事では、C++STLのset::upper_bound()、それらの構文、動作、および戻り値について説明します。
C ++ STLの設定とは何ですか?
C ++ STLのセットは、一般的な順序で一意の要素を持つ必要があるコンテナーです。要素の値は要素を識別するため、セットには一意の要素が必要です。セットコンテナに値を追加すると、後で変更することはできませんが、値を削除したり、セットに追加したりすることはできます。セットは二分探索木として使用されます。
何が設定されていますか::upper_bound()?
upper_bound()は、
構文
name_of_set.upper_bound(const type_t&value);
パラメータ
この関数は、パラメーター、つまり上限が検出される値を受け入れます。
戻り値
この関数は、値より大きい次の要素を指すイテレータを返します
例
Input: set<int> myset = {1, 2, 3, 4, 5};
Myset.upper_bound(3);
Output: Upper bound = 4 例
#include <bits/stdc++.h>
using namespace std;
int main(){
set<int> Set;
Set.insert(9);
Set.insert(7);
Set.insert(5);
Set.insert(3);
Set.insert(1);
cout<<"Elements are : ";
for (auto i = Set.begin(); i!= Set.end(); i++)
cout << *i << " ";
auto i = Set.upper_bound(5);
cout <<"\nupper bound of 5 in the set is: ";
cout << (*i) << endl;
i = Set.upper_bound(1);
cout<<"upper bound of 1 in the set is: ";
cout << (*i) << endl;
return 0;
} 出力
上記のコードを実行すると、次の出力が生成されます-
upper bound of 5 in the set is: 7 upper bound of 1 in the set is: 3
例
#include <iostream>
#include <set>
int main (){
std::set<int> Set;
std::set<int>::iterator one, end;
for (int i=1; i<10; i++)
Set.insert(i*10);
one = Set.lower_bound (20);
end = Set.upper_bound (40);
Set.erase(one , end); // 10 20 70 80 90
std::cout<<"Elements are: ";
for (std::set<int>::iterator i = Set.begin(); i!=Set.end(); ++i)
std::cout << ' ' << *i;
std::cout << '\n';
return 0;
} 出力
上記のコードを実行すると、次の出力が生成されます-
Elements are : 10 50 60 70 80 90
-
C ++ STLのatan2()関数
atan2()関数は、yとxに関する座標の正接逆関数を返します。ここで、yとxは、それぞれy座標とx座標の値です。これはC++STLに組み込まれている関数です。 atan2()関数の構文は次のとおりです。 atan2(dataType var1, dataType var2) 構文からわかるように、関数atan2()は、データ型floatの2つのパラメーターvar1とvar2、それぞれyとxポイントであるdoubleまたはlongdoubleを受け入れます。 atan2()によって返される値は、-piからpiの範囲であり、(x、y)と正のx軸の間の角度です。 C ++でatan2()を
-
C ++ STLのacos()関数
acos()関数は、ラジアンで指定された角度の逆コサインを返します。これはC++STLに組み込まれている関数です。 acos()関数の構文は次のとおりです。 acos(var) 構文からわかるように、関数acos()は、データ型float、double、またはlongdoubleのパラメーターvarを受け入れます。このパラメーターの値は-1から1の間でなければなりません。これは、-piからpiの範囲のvarの逆コサインを返します。 C ++でacos()を示すプログラムは次のとおりです。 例 #include <iostream> #include <cmath>