• c++ 适配器


    #include <bits/stdc++.h>
    using namespace std;
    const int MAX = 1e5+10;
    vector<int> filter(const vector<int> &vec,int val,less<int> &lt) {
        vector<int> nvec;
        vector<int> :: const_iterator iter=vec.begin();
        while((iter=find_if(iter,vec.end(),bind2nd(less<int>(),val)))!=vec.end()) {
            nvec.push_back(*iter);
            iter++;
        }
        return nvec;
    }
    template<typename InputIterator ,typename OutputIterator,typename ElemType,typename Comp>
    OutputIterator filter(InputIterator first,InputIterator last,OutputIterator at,const ElemType val,Comp pre) {
        while((first=find_if(first,last,bind2nd(pre,val)))!=last) {
            cout<<*first<<endl;
            *at++=*first++;
        }
        return at;
    }
    template<typename InputIterator,typename OutputIterator,typename ElemType>
    OutputIterator sub_vec(InputIterator first,InputIterator last,ElemType val,OutputIterator at) {
        InputIterator first1=first,last1=last;
        for(;first!=last;first++) {
            *at++=*first++;
        }
        sort(first1,last1);
        first=find_if(first1,last1,bind2nd(less<int>(),val));
        at->erase(first,last1);
        return at;
    }
    priority_queue <int,vector<int>,greater<int> > q;

    int main() {
        const int elem_size=5;
        int ia[elem_size]={1,3,4,56,7};
        vector<int> res(ia,ia+elem_size);
        vector<int> ans;
        filter(res.begin(),res.end(),back_inserter(ans),20,greater<int>());
        for(int i=0;i<ans.size();i++) {
            printf("%d ",ans[i]);
        }
    }
  • 相关阅读:
    LR常用函数汇总
    常用工具软件包下载地址
    MySQL分表操作的例子
    Redis性能优化之redis.cnf配置参数
    Redis监控之redis-live.conf配置
    Oracle中查询和定位数据库问题的SQL语句
    Oracle种常用性能监控SQL语句
    show processlist使用介绍
    MySQL流程控制和存储过程介绍
    MySQL字符集和排序介绍
  • 原文地址:https://www.cnblogs.com/acvc/p/4620638.html
Copyright © 2020-2023  润新知