/ * STL sorted * / #include <the iostream> #include <Map> #include <Vector> #include <List> #include <algorithm> the using namespace STD; struct STComp: public a binary_function < int , int , BOOL > { inline BOOL operator () ( int X, int Y) { // returns true, indicating that without changing the position, descending order return X> Y; } }; struct STPrint :public unary_function<int, bool> { inline void operator()(int x) { cout << x << " " ; } }; void test1() { vector<int> v1 = { 1,2,3,4,5,6,7,8 }; //vector排序 sort(v1.begin(), v1.end(), STComp()); for_each(v1.begin(), v1.end(), STPrint()); } void test2() { std::list<int> alist; alist.push_back(3); alist.push_back(4); alist.push_back(2); alist.push_back(7); alist.push_back(9); alist.push_back(1); //list排序 alist.sort(STComp()); for_each(alist.begin(), alist.end(), STPrint()); } int main() { test2(); getchar(); return 0; }