美文网首页
set_helper

set_helper

作者: 我才是helo | 来源:发表于2017-11-27 11:49 被阅读0次
//
// Created by herohlc  on 2017/11/26.
//

#ifndef SET_HELPER_H_
#define SET_HELPER_H_

#include <iostream>

#include <set>
#include <algorithm>
#include <functional>

using std::cout;
using std::endl;
using std::set;
using std::multiset;

template <class T>
class StatisticSet{
public:
    StatisticSet(){}

    void add(T item) {
        statistic_set_.insert(item);
        history_set_.insert(item);

        cout << statistic_set_.count(item) << endl;
    }

    void del(T item) {
        cout << statistic_set_.count(item) << endl;
        statistic_set_.erase(item);
    }

    void ask(T item) const {
        cout << ((history_set_.find(item) != history_set_.end())? 1 : 0 ) << " " << statistic_set_.count(item) << endl;
    }

    void test() const{
        cout << "--------------------------" << endl;
        for(auto itr : statistic_set_){
            cout << itr << endl;
        }
        cout << "--------------------------" << endl;
    }

private:
    StatisticSet( const StatisticSet&) {}
    StatisticSet& operator = (const StatisticSet&){}

private:
    set<T>      history_set_;
    multiset<T> statistic_set_;

};

#endif // SET_HELPER_H_

相关文章

网友评论

      本文标题:set_helper

      本文链接:https://www.haomeiwen.com/subject/edwrbxtx.html