对std::map进行排序

1、对Key排序。

  std::map的第三个参数即为对key进行排序的比较函数。默认为less,表示升序。如果要降序,可以改为greater。

2、对Value排序

      不支持,因为map不是一个序列的容器。如果真要排序,需要转为一个保存pair的vector,再排序。

      不过这样性能就受损了,建议更换容器。

详细参考:

https://blog.csdn.net/puqutogether/article/details/41889579

http://www.cplusplus.com/reference/map/map/

猜你喜欢

转载自www.cnblogs.com/aoyihuashao/p/9430086.html
今日推荐