1) Map sort by key:
using function pointer
bool key_compare(int a, int b){
return (a > b);
}
int main() {
bool(*fn_cmp)(int, int) = key_compare;
map<int,int,bool(*)(int,int)> m(fn_cmp);
}
2) Map sort by value:
http://www.technical-recipes.com/2012/how-to-sort-items-contained-in-stl-maps/
3) Priority_queue
struct Node {
int val;
int freq;
Node(int x): val(x), freq(1) {}
};
struct my_compare {
bool operator() (Node const &a, Node const &b) const {
return a.freq < b.freq;
}
};
typedef std::priority_queue<Node*, std::vector<Node*>, my_compare> freq_queue;
int main() {
freq_queue q;
return 0;
}