#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是使用树结构来实现的。