multiset多重集合容器
#include <iostream>>
#include <set> //multiset头文件
//#include <string>
using namespace std;
//允许重复的元素值插入
//前序遍历:根左右
//中序遍历 左根右
//后序遍历 左右根
int main()
{
//插入重复键值123并中序遍历multiset对象
multiset<string> ms;
ms.insert("abc");
ms.insert("123");
ms.insert("111");
ms.insert("aaa");
ms.insert("123");
multiset<string>::iterator it;
for(it=ms.begin();it!=ms.end();it++)
{
cout << *it << endl;
}cout << endl;
//multiset元素的删除
//删除值为123的所有重复元素并返回删除元素总数
int n=ms.erase("123");
cout << "删除元素总数为:" << n << endl;
//删除后的元素
for(it=ms.begin();it!=ms.end();it++)
{
cout << *it << endl;
}cout << endl;
//multiset元素的查找
//查找键值“123”
it=ms.find("123");
if(it!=ms.end())//找到
{
cout << *it << endl;
}
else //没有找到
{
cout << "not find it!" << endl;
}
return 0;
}