33 lines
670 B
C++
33 lines
670 B
C++
|
#include <iostream>
|
||
|
#include <set>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
template <typename T>
|
||
|
void print(const set<T> &s)
|
||
|
{
|
||
|
for (typename set<T>::const_iterator it = s.begin(); it != s.end(); ++it)
|
||
|
cout << *it << ' ';
|
||
|
cout << endl;
|
||
|
}
|
||
|
|
||
|
template <typename T>
|
||
|
void print(const multiset<T> &s)
|
||
|
{
|
||
|
for (typename multiset<T>::const_iterator it = s.begin(); it != s.end(); ++it)
|
||
|
cout << *it << ' ';
|
||
|
cout << endl;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int m[] = {1, 2, 3, 2, 3, 4};
|
||
|
set<int> s(m, m + 6);
|
||
|
print(s); // set 会自动去重,输出 1 2 3 4
|
||
|
|
||
|
multiset<int> ms(m, m + 6);
|
||
|
print(ms); // multiset 不会自动去重,输出 1 2 2 3 3 4
|
||
|
|
||
|
return 0;
|
||
|
}
|