struct nnum{ //重载() bool operator () (int v1,int v2){ return v1>v2; } }; set<int,nnum> num;//仿函数对set自定义排序,默认递增排序
template<class T,class T2> void printSet(set<T,T2> &a) { for (auto it = a.begin(); it != a.end(); ++it) { cout << (*it) << endl; } } //仿函数 class myComper { public: //重载() bool operator()(int v1, int v2) { return v1 > v2; } }; void test04() { //从大到小的排序 //set<int,数据类型> iset = { 1,2,3,5,6,9,4,7,8 };所以这块需要仿函数 set<int, myComper> iset; iset = { 1,2,3,5,6,9,4,7,8 }; printSet(iset); }