首页 > 其他 > 详细

STL set,mulityset用法

时间:2014-01-25 20:04:37      阅读:434      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include<iostream>
#include <set>
using namespace std;
template <class T>
class RuntimeCmp
{
public:
    enum cmp_mode {normal,reverse};
private:
    cmp_mode m_mode;
public:
    RuntimeCmp(cmp_mode m = normal):m_mode(m){};
    bool operator () (const T& t1,const T& t2) 
    {
        return m_mode == normal ? t1 < t2 : t1>t2;
    }
    bool operator == (const RuntimeCmp& rc)
    {
        return m_mode = rc.m_mode;
    }
};

typedef std::set<int,RuntimeCmp<int>> IntSet;

int _tmain(int argc, int argv[])
{
    IntSet intSet;
    intSet.insert(3);
    intSet.insert(1);
    intSet.insert(4);
    int aa = 0;

} 

set是使用树结构来实现的。
bubuko.com,布布扣

STL set,mulityset用法

原文:http://www.cnblogs.com/sdnyzhl/p/3533351.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!