samedi 1 février 2020

how to get the third element (from the beginning and from the end) in a map c++

I want to access the third element(both in forward and reverse order) without iterating the map.

int main() {
map<int,int>mp;
vector<int>v={1,4,2,5,4,2,5,7,6,9,7,9,8};
for(int i=0;i<v.size();++i)
{
    mp[v[i]]++;
}
return 0;

}

here the expected output would be 4 2 and 7 2.

Aucun commentaire:

Enregistrer un commentaire