C++ set 与multiset 关联式容器

set

#include 
#include 
using namespace std;
int main() {
    int sz[9] = { 1,3,4,1,1,1,1,1,1};
    set A(sz, sz + 9);
    set::iterator se = A.begin();
    cout << "sets elem numbers: " << A.size() << endl;
    while (se!=A.end())
    {
        cout << *se << " ";
        ++se;
    }
    system("pause");
    return 0;
}
输出
  • 关键字唯一,且按升序排列

multiset

#include 
#include 
using namespace std;
int main() {
    int sz[9] = { 1,3,4,1,1,1,1,1,1};
    multiset A(sz, sz + 9);
    set::iterator se = A.begin();
    cout << "sets elem numbers: " << A.size() << endl;
    while (se!=A.end())
    {
        cout << *se << " ";
        ++se;
    }
    system("pause");
    return 0;
}
输出
  • 元素可以重复,且升序输出

你可能感兴趣的:(C++ set 与multiset 关联式容器)