STLmap使用总结。

来源:互联网 发布:java工程师最大年龄 编辑:程序博客网 时间:2024/06/09 17:06

Map 删除掉value值为给定值的节点。

方法一:

void removeValueForMap1(map<int,int> &ans,int value){    for (auto it = ans.begin(); it!=ans.end();) {        if(it->second == value){            auto tmp = it;            it++;            ans.erase(tmp);        }        else            it++;    }}
方法二

class cmp{//先定义仿函数。    int m_value;public:    cmp(int value):m_value(value){}    bool operator()(map<int,int,less<int> >::value_type &pair){        return pair.second == m_value;    }};


Map的排序:





0 0
原创粉丝点击