c++ sorted set code example
Example 1: c++ set sort order
struct cmpStruct {
bool operator() (int const & lhs, int const & rhs) const
{
return lhs > rhs;
}
};
std::set<int, cmpStruct > myInverseSortedSet;
Example 2: set c++
#include <iostream>
#include <set>
bool fncomp (int lhs, int rhs) {return lhs<rhs;}
struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return lhs<rhs;}
};
int main ()
{
std::set<int> first;
int myints[]= {10,20,30,40,50};
std::set<int> second (myints,myints+5);
std::set<int> third (second);
std::set<int> fourth (second.begin(), second.end());
std::set<int,classcomp> fifth;
bool(*fn_pt)(int,int) = fncomp;
std::set<int,bool(*)(int,int)> sixth (fn_pt);
return 0;
}