示例:
#include<iostream>
using namespace std;
#include<list>
#include<algorithm>
bool Compore(int v1, int v2)
{
return v1 > v2;
}
void printList(const list<int> &L)
{
for (list<int>::const_iterator it = L.begin(); it != L.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
list<int>L1;
//插入数据
L1.push_back(30);
L1.push_back(20);
L1.push_back(70);
L1.push_back(50);
L1.push_back(60);
printList(L1);
//反转排序
L1.reverse();
printList(L1);
//sort排序 默认为升序
L1.sort();
printList(L1);
//L1.reverse();
//printList(L1);
//降序排序
L1.sort(Compore);
printList(L1);
}
int main()
{
test01();
return 0;
}
总结:
1.反转 reverse();
2.排序 sort(成员函数);