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/

 

相关文章:

  • 2021-10-30
  • 2022-12-23
  • 2021-09-29
  • 2021-08-27
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案