阅读读程序(3)

来源:互联网 发布:发那科机器人编程培训 编辑:程序博客网 时间:2024/05/17 23:51
*Copyright (c) 2014,烟台大学计算机学院

*All right reserved.

*文件名称:test.cpp

*作    者:韩双志

*完成日期:2016年6月16日

*版本号:v1.0

*

*问题描述:multiset用法

*输入描述:无

*输出描述:输出相应的结果

/*

#include <algorithm>
#include<set>
#include<iterator>
#include<iostream>
using namespace std;
int main()
{
    multiset<int>eg1;
//插入
    eg1.insert(1);
    eg1.insert(100);
    eg1.insert(5);
    eg1.insert(1);//是否插入
    eg1.insert(10);
    eg1.insert(9);
//遍历set,可以发现元素是有序的
    multiset<int>::iterator set_iter=eg1.begin();
    cout<<"Set named eg1:"<<endl;
    for(; set_iter!=eg1.end(); set_iter++)
        cout<<*set_iter<<" ";
    cout<<endl;
//使用size()函数可以获得当前元素个数
    cout<<"Now there are "<<eg1.size()<<" elements in the set eg1"<<endl;
    if(eg1.find(200)==eg1.end())//find()函数可以查找元素是否存在
        cout<<"200 isn't in the set eg1"<<endl;
    return 0;
}

*/

运行结果:

 

知识点总结

multiset是<set>库中一个非常有用的类型,它可以看成一个序列,插入一个数,删除一个数都能够在O(logn)的时间内完成,而且他能时刻保证序列中的数是有序的,而且序列中可以存在重复的数

0 0