取反适配器

#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
//取反适配器
//not2二元取反适配器

struct Compare :public binary_function<int,int,bool>
{
    bool operator()(int a,int b)const
    {
        return a > b;
    }
};

struct Output
{
    void operator()(int v)
    {
        cout << v << endl;
    }
};
int main()
{
    vector<int> v;
    for (int i = 0; i < 5; i++)
    {
        v.push_back(rand() % 100);
    }
    sort(v.begin(), v.end(), Compare());
    for_each(v.begin(), v.end(), Output());

    //去反适配器
    sort(v.begin(), v.end(), not2(Compare()));
    for_each(v.begin(), v.end(), Output());
}

 

posted @ 2021-12-14 16:28  小康规划  阅读(39)  评论(0)    收藏  举报