Sorting in second parameter in map

unordered_map<ll,vector> extra;
for(auto p:extra){
can someone tell me how to sort the vector when it is taken as key in map

I don’t know what your actual code looks like as you haven’t formatted it, but in the code you’ve provided, for it to work p should be taken by reference, not value.


#include <unordered_map>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main()
    unordered_map<int,vector<int>> extra;
    extra[5] = {1,7,6,4};
    for(auto& p:extra){
    for (const auto& x : extra[5])
        cout << x << " ";
    cout << endl;
1 Like

thanks mahn!

1 Like