C++ STL容器Map的按Key排序和按Value排序
1、按Key排序
我们知道,map内部本身就是按序存储的(红黑树),在我们插入<key, value>键值对时,就会按照key的大小顺序进行存储。这也是作为key的类型必须能够进行<运算比较的原因。现在我们用string类型作为key,因此,我们的存储就是按string的字典排序储存的。
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main(
原创
2020-09-07 10:33:40 ·
1924 阅读 ·
0 评论