版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CosmopolitanMe/article/details/87721756
#include <iostream>
#include <deque>
#include <list>
using namespace std;
std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list)
{
for (auto &i : list) {
ostr << " " << i;
}
return ostr;
}
int main()
{
list<int> l={3,2,1,6,8,0,1,5,9};
l.sort(); //默认从小到大排序
cout << l << endl;
l.sort(greater<int>()); //从大到小排序
cout << l << endl;
return 0;
}