unordered_map与map的区别
unordered_map的底层用哈希表实现,所以无序
map的底层用红黑树实现,有序
unordered_map的遍历方法
//1
for (pair<string,int> kv:cnt){
cout<<kv.first+":"<<kv.second<<endl;
}
//2
for (const pair<string,int> & kv:cnt){
cout<<kv.first+":"<<kv.second<<endl;
}
//3
for (auto kv:cnt){
cout<<kv.first+":"<<kv.second<<endl;
}
//4
for (auto & kv:cnt){
cout<<kv.first+":"<<kv.second<<endl;
}
//5
for(unordered_map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++){
cout<<it->first+":"<<it->second<<endl;
}