//reverse反转list中元素
//sort排序algorithrm
//所有不支持随机访问迭代器不能用标准算法,但是内部会提供相应算法
#include<iostream>
#include<list>
#include<time.h>
using namespace std;
void print(const list<int>& h) {
for (list<int>::const_iterator it = h.begin(); it != h.end(); it++)
cout << *it << " ";
cout << endl;
}
bool mycompare(int a, int b) {
return a > b;
}
int main() {
list<int> h;
time_t ti = time(NULL);
srand(ti);
for (int i = 0; i < 10; i++)
h.push_back(rand() % 11);
print(h);
h.reverse();
cout << "反转后" << endl;
print(h);
h.sort();
cout << "递增排序后" << endl;
print(h);
h.sort(mycompare);
cout << "递减排序后" << endl;
print(h);
return 0;
}