C++的map排序 |
您所在的位置:网站首页 › 自动排序功能 › C++的map排序 |
一 点睛 map的排序默认按照key从小到大进行排序,但有以下几点需要注意: 1 按照key从大到小进行排序。 2 key的第1个元素是结构体。 3 想按value(第二个元素)排序。 二 让map中的元素按照key从大到小排序 1 代码 #include #include #include using namespace std; int main(){ map mapStudent; //关键是这句话 mapStudent["LiMin"]=90; mapStudent["ZiLinMi"]=72; mapStudent["BoB"]=79; map::iterator iter=mapStudent.begin(); for(iter=mapStudent.begin();iter!=mapStudent.end();iter++) { cout |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |