* create
```
#include <set>
using namespace std;
struct classComp {
bool operator() (int l, int r) { return l<r; }
};
bool funComp(int l, int r) { return l<r; }
int main () {
multiset<int> a; // default constructor
multiset<int> b(a); // copy constructor
multiset<int> c(move(a)); // move constructor
multiset<int> d{1,2,3}; // initializer list constructor
// multiset has no fill constructor
multiset<int> f(a.begin(),a.end()); // range constructor
multiset<int>* g = new multiset<int>{1,2,3}; // new operator
delete g;
multiset<int,classComp> mc;
multiset<int,decltype(&funComp)> mf(&funComp);
}
```
* iterator
```
#include <iostream>
#include <set>
using namespace std;
int main (){
multiset<int> s{1,2,3,4,5,1};
for (auto it=s.begin(); it!=s.end(); ++it)
cout<<*it<<",";
cout<<endl;
for (auto it=s.cbegin(); it!=s.cend(); ++it)
cout<<*it<<",";
cout<<endl;
for (auto it=s.rbegin(); it!=s.rend(); ++it)
cout<<*it<<",";
cout<<endl;
for (auto it=s.crbegin(); it!=s.crend(); ++it)
cout<<*it<<",";
cout<<endl;
}
/*
1,1,2,3,4,5,
1,1,2,3,4,5,
5,4,3,2,1,1,
5,4,3,2,1,1,
*/
```
* add
```
#include <iostream>
#include <set>
using namespace std;
int main ()
{
multiset<int> s;
s.insert(1);
s.emplace(3);
for (auto &i:s)
cout<<i<<",";
cout<<endl;
}
// 1,3,
```
* change
```
#include <iostream>
#include <set>
using namespace std;
void p(multiset<int>& a) {
for(auto &i:a) cout<<i<<";";
cout<<endl;
}
int main ()
{
multiset<int> a{1,2,3,4,5};
multiset<int> a1(a), a2(a);
a.swap(a1);
p(a);
}
```
* query
```
#include <iostream>
#include <set>
using namespace std;
int main() {
multiset<int> s{1,2,3,4,5,6,1,2,3};
auto it=s.find(2);
if(it!=s.end()) cout<<"found"<<endl;
cout<<s.count(2)<<endl;
auto itl = s.lower_bound(3);
it=s.begin();
while(it!=itl){
cout<<*it++<<",";
}
cout<<endl;
it=s.upper_bound(3);
while(it!=s.end()) {
cout<<*it++<<",";
}
cout<<endl;
auto r=s.equal_range(3);
for(auto it=r.first; it!=r.second; it++)
cout<<*it<<",";
cout<<endl;
cout<<s.empty()<<endl;
cout<<s.size()<<endl;
cout<<s.max_size()<<endl;
}
/*
found
2
1,1,2,2,
4,5,6,
3,3,
0
9
230584300921369395
*/
```
* delete
```
#include <set>
using namespace std;
int main () {
multiset<int> s{1,2,3,4,5,1,2,3};
s.erase(s.begin());
s.erase(4);
s.clear();
}
```