仿函数就是用来控制排列顺序的 map<int,int,Compare>是这样,list.sort()也是这样.
// List双向链表.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<list>
using namespace std;
struct Compare
{
bool operator()(const int& a, const int& b)const
{
return a < b;
}
};
int main()
{
list<int>MyArr;
MyArr.push_back(9);
MyArr.push_back(1);
MyArr.push_back(2);
MyArr.push_back(23);
MyArr.push_back(12);
MyArr.push_back(32);
MyArr.push_back(6);
MyArr.sort(Compare());
for (auto it=MyArr.begin();it!=MyArr.end();++it)
{
cout << *it << endl;
}
}
标签:sort,const,函数,传入,int,back,push,MyArr From: https://www.cnblogs.com/VisionSeven/p/18085962