Files
Data-Structure/STL/STL-Set/multiset.cpp
2025-08-13 12:09:59 +08:00

42 lines
831 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <set>//也是set
using namespace std;
class compare{
public:
template <class T>
bool operator()(const T& a, const T& b){
return a > b;
}
};
int main(){
auto cmpl = [](auto a, auto b){
return a < b;
};
multiset<int> a{1,1,2,3,3,3,4,5,6,7,7,7,10};
multiset<int, decltype(cmpl)> b(cmpl);
b.insert({14,16,20,18,2,2,2,4,4,6,6,8,8,10,12});
multiset<int, compare> c{1,3,5,7,9,11,11,11,13};
for(int x : a){
cout << x << " ";
}cout << endl;
for(int x : b){
cout << x << " ";
}cout << endl;
for(int x : c){
cout << x << " ";
}cout << endl;
cout << b.count(2) << endl;
cout << *b.upper_bound(6) << " " << *b.lower_bound(6) << endl;
return 0;
}
/*
1 1 2 3 3 3 4 5 6 7 7 7 10
2 2 2 4 4 6 6 8 8 10 12 14 16 18 20
13 11 11 11 9 7 5 3 1
3
8 6
*/
//基本用法与set一致可以有多个重复元素