multiset
多重集合
std::multiset is an associative container that contains a sorted set of objects of type Key. Unlike set, multiple keys with equivalent values are allowed. Sorting is done using the key comparison function Compare. Search, insertion, and removal operations have logarithmic complexity.
它与set
的区别在于,它允许重复的值。
代码示例,
#include <iostream>
#include <set>
using namespace std;
int main() {
multiset<int> a;
a.insert(1);
a.insert(3);
a.insert(2);
a.insert(2);
a.insert(2);
for (auto it = a.begin(); it != a.end(); it++) {
cout << *it << endl;
}
return 0;
}
程序输出为,
1
2
2
2
3