C ++多重集合の研究ノート

https://www.luogu.org/blog/yu123123/Templet

セットと多重集合の要素は、特定の並べ替え原理に従ってソートされます。両者の違いという点で、可能多重集合は要素を繰り返し、セットは一意でなければなりません。

基本的な操作機能:

1.Basics

セット/マルチセットを作成します。

例えば、ここで多重集合:

マルチセット<整数>秒;

int型はマルチセットクラスを作成します

s.max_sizeは()を収容するための要素の数を返します

()コンテナs.sizeの要素の現在の数を

s.empty()は、コンテナが空であるか否かを判断します

2.特殊な検索機能

マルチセット<int型、大きい<int型>> S、タイプの降順を作成

マルチセット<int型、少ない<int型>> S;大型タイプ(つまりデフォルト)に小型の並べ替えを作成します

s.begin()、s.end()。

Sリターンヘッダ/テールイテレータ

s.count(x)は、問い合わせの数がコンテナ要素Xを表示さ

s.find(x)はxの位置におけるコンテナエレメントを照会最初に返されない場合s.end(表示)。

s.lower_bound(x)は、イテレータを返すの符号は、x以上の第1の要素の位置に現れます

s.upper_bound(x)は、x sはに表示されるよりもイテレータ、最初のマーキング要素の位置を返します

s.insert(x)はxがコンテナ要素の中に挿入されています

用(多重集合<整数> :: =)イテレータ(ITをs.begin;それは(= s.end);! IT ++)
のprintf( "%のD"、IT *);容器を通過する方法よ

s.erase()パラメータなしで全体のコンテナは、すべての要素を削除します!

s.erase(POS)は、要素のイテレータposが指摘削除されます

s.erase(L、R)は、区間[L、R)のすべての要素を削除します!

https://www.jianshu.com/p/ecd7f66e11d3

#include <set>  
#include <iostream> using namespace std; int main() { ///1. 初始化 multiset<int> num; multiset<int>::iterator iter,beg,end; cout << num.max_size() << endl;///multiset容纳上限 cout << endl; ///2. 添加元素 for (int i = 0; i < 10; i++) num.insert(i); cout << num.size() << endl; cout << endl; ///3. 遍历 for (iter = num.begin(); iter != num.end(); iter++) cout << *iter << " " ; cout << endl; cout << endl; ///4. 查询 iter = num.find(1); if (iter != num.end()) cout << *iter << endl; else cout << -1 << endl; iter = num.find(99); if (iter != num.end()) cout << *iter << endl; else cout << -1 << endl; cout << endl; beg=num.lower_bound(2); end=num.upper_bound(7); for (; beg != end; beg++) cout << *beg << " " ; cout << endl; ///5. 删除 iter = num.find(1); num.erase(iter); cout << num.size() << endl; for (iter = num.begin(); iter != num.end(); iter++) cout << *iter << " " ; cout << endl; cout << endl; ///6. 判空与清空 if (!num.empty()) num.clear(); } 

 

 

おすすめ

転載: www.cnblogs.com/little-cute-hjr/p/11797527.html