#include<iostream>
#include<list>
#include<algorithm>//标准算法头文件
using namespace std;
//list容器的反转和排序
void printlist(const list<int>& L) {
for (list<int>::const_iterator it = L.begin(); it != L.end(); it++) {
cout << *it << " ";
}
cout << endl;
}
bool compare(int v1, int v2) {//按照降序排列
return v1 > v2;//降序就让第一个数大于第二个数
}
void test() {
list<int>l;//默认构造
l.push_back(20);
l.push_back(10);
l.push_back(30);
cout << "反转前" << endl;
printlist(l);
//反转
l.reverse();
cout << "反转后" << endl;
printlist(l);
//排序
cout << "排序前" << endl;
printlist(l);
//所有不支持随机访问迭代器的容器不支持标准算法
//不支持随机访问迭代器的容器内部会提供对应的算法
//sort(l.begin(), l.end()); 不支持全局函数排序
l.sort(compare);//默认排序从小到大
cout << "排序后" << endl;
printlist(l);
}
int main() {
test();
system("pause");
return 0;
}