I am doing a c++ project and I am getting many errors in the following function that…
Jump to turn (8)
- 1I am doing a c++ project and I am getting many errors in the following function
- 2it doesn't work I changed to a.second < b.second to make it descending order but
- 3it gives the same order so it is still wrong, what could be the error? This is h
- 4you just wrote the same code as before without changes so it still won't work
- 5not it has the same order as before but ascending, it is still giving me weird o
- 6can you do it without using the auto keyword?
- 7ir works perfectly but it is just too much code, can it be done in a simpler way
- 8no, this simpler way has the same problem as before the wrong order of 2's and 1
- User
I am doing a c++ project and I am getting many errors in the following function that orders an unordered_map based on its key values, can you help me do it correctly:
void SortMap(std::unordered_map<wxString, int>* unorderedMap) { std::sort(unorderedMap->begin(), unorderedMap->end(), (const pair<string, int>& a, const pair<string, int>& b) { return a.second > b.second; }); }
- Assistant
Here's a corrected version of the function:
void SortMap(std::unordered_map<wxString, int>* unorderedMap) { std::vector<std::pair<wxString, int>> vec(unorderedMap->begin(), unorderedMap->end());
code