//map容器排序
#include<iostream>
using namespace std;
#include<map>
class MyCompare
{
public:
bool operator()(int v1, int v2)
{
//降序
return v1 > v2;
}
};
void test01()
{
map<int,int,MyCompare>m;
m.insert(make_pair(1, 10));
m.insert(make_pair(2, 10));
m.insert(make_pair(3, 10));
m.insert(make_pair(4, 10));
m.insert(make_pair(5, 10));
for (map<int, int>::iterator it = m.begin(); it != m.end(); it++)
{
cout << "key = " << it->first << " value = " << it->second << endl;
}
}
int main()
{
test01();
system("pause");
return 0;
}
3.9.6 map容器排序
最新推荐文章于 2024-01-21 23:13:38 发布