• list-sort1


    ////////////////////////////////////////
    //      2018/04/27 7:26:06
    //      list-sort1
    
    // sorts the list
    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <functional>
    
    using namespace std;
    
    template <class T>
    class Print{
    public:
        void operator()(T& t){
            cout << t << " ";
        }
    };
    //=====================
    int main(){
        int ary[] = { 3, 2, 5, 7, 3, 6, 7, 2, 4, 5 };
        list<int> li(ary, ary + 10);
        Print<int> print;
    
        cout << "Before sorting
     li:";
        for_each(li.begin(),li.end(), print);
        cout << endl;
    
        li.sort(greater<int>());
        cout << "After li.sort(greater<int>())
    li:";
        for_each(li.begin(), li.end(), print);
        cout << endl;
    
        li.sort(less<int>());
        cout << "After li.sort(less<int>())
    li:";
        for_each(li.begin(), li.end(), print);
        cout << endl;
    
        return 0;
    }
    /*
    OUTPUT:
        Before sorting
        li:3 2 5 7 3 6 7 2 4 5
        After li.sort(greater<int>())
        li:7 7 6 5 5 4 3 3 2 2
        After li.sort(less<int>())
        li:2 2 3 3 4 5 5 6 7 7
    */ 
    
    /*
    
    // TEMPLATE STRUCT greater
        emplate<class _Ty>
        struct greater
            : public binary_function<_Ty, _Ty, bool>
        {   // functor for operator>
            bool operator()(const _Ty& _Left, const _Ty& _Right) const
            {   // apply operator> to operands
                return (_Left > _Right);
            }
        };
    
        // TEMPLATE STRUCT less
        emplate<class _Ty>
            struct less
                : public binary_function<_Ty, _Ty, bool>
        {   // functor for operator<
            bool operator()(const _Ty& _Left, const _Ty& _Right) const
            {   // apply operator< to operands
                return (_Left < _Right);
            }
        };
    */
  • 相关阅读:
    线段树----hdoj 1754 I here it
    树状数组----poj 2352 stars
    莫队算法
    枚举+深搜----poj 3279 Fliptile
    java 10 -09的作业
    java 09 06 thread-同步代码块-同步方法
    java09-05 join_daemon
    java09 02 Thread-yield 放弃
    java 07 jar
    java 08 作业
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537934.html
Copyright © 2020-2023  润新知