- vector的使用
- list的使用
- deque的使用
- set的使用
- map的使用
- multiset的使用
- multimap的使用
#include <set>
#include <iostream>
using namespace std;
int main()
{
///1. 初始化
multiset<int> num;
multiset<int>::iterator iter,beg,end;
cout << num.max_size() << endl;///multiset容纳上限
cout << endl;
///2. 添加元素
for (int i = 0; i < 10; i++)
num.insert(i);
cout << num.size() << endl;
cout << endl;
///3. 遍历
for (iter = num.begin(); iter != num.end(); iter++)
cout << *iter << " " ;
cout << endl;
cout << endl;
///4. 查询
iter = num.find(1);
if (iter != num.end())
cout << *iter << endl;
else
cout << -1 << endl;
iter = num.find(99);
if (iter != num.end())
cout << *iter << endl;
else
cout << -1 << endl;
cout << endl;
beg=num.lower_bound(2);
end=num.upper_bound(7);
for (; beg != end; beg++)
cout << *beg << " " ;
cout << endl;
///5. 删除
iter = num.find(1);
num.erase(iter);
cout << num.size() << endl;
for (iter = num.begin(); iter != num.end(); iter++)
cout << *iter << " " ;
cout << endl;
cout << endl;
///6. 判空与清空
if (!num.empty())
num.clear();
}
网友评论