I'm trying to sort a vector of maps by its stored value (not key) in descending order. Each index will have a series of addresses stored there, along with a key to keep track of which address was recently placed at that particular index location in the vector. I know that the sorting usually takes place based on the key and not the value. The reason why I cannot sort based on the key is because the keys are addresses and the values are the number of times the address has been encountered. As a result, I use the key to find the address, and then update its value with the current count. In the end, I would like to order and print out the addresses from the most frequently encountered to the less frequently encountered. I tried making my own "sort" function with a value comparator. This is the code I have so far:
1 2 3 4 5 6 7 8 9
|
void sortIndex(uint32_t index, vector<map<uint32_t, int> >& table)
{
sort(table.at(index).begin(), table.at(index).end(), &maxValue);
}
bool maxValue(pair<uint32_t, int> i, pair<uint32_t, int> j)
{
return i.second > j.second;
}
|
Unfortunately I keep getting the following errors from VS2013 "algorithm.h" file:
Compiler Error C2784: 'declaration' : could not deduce template argument for 'type' from 'type'. The compiler cannot determine a template argument from the supplied function arguments.
Compiler Error C2676: binary 'operator' : 'type' does not define this operator or a conversion to a type acceptable to the predefined operator. To use the operator, you must overload it for the specified type or define a conversion to a type for which the operator is defined.
Compiler Error C2780: 'declaration' : expects number1 arguments - number2 provided. A function template has too few arguments.
If the errors were in my code directly, I could solve them since I wrote it and would just modify it. But, the errors are from one of the header files, so I cannot figure out the exact source of my problem to correct it. My only assumption is that the issues lie within my sort statements. I've researched how to implement the value sort and fix my compiling issues with no luck. Is there a way I can sort a map based on its value?
Thanks!