码迷,mamicode.com
首页 > 编程语言 > 详细

STL list 使用find_if查找算法

时间:2015-04-24 19:37:55      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:public   return   


set和multiset map和multimap 有成员函数find函数可快速查找


vector和list 没有find函数想要查找通过迭代器遍历


以下使用类重载运算符实现find_if快速查找:


typedef struct strTmpLinkMan

{

CString TmpLinkManName;

CString TmpLinkManeEmail;

}strTmpLinkMan;

typedef std::list<strTmpLinkMan> TmpLinkMan_t;

typedef std::list<strTmpLinkMan>::iterator TmpLinkManIter_t;


class FindthevalString

{

//STL查找TmpLinkManEmail是否含有

public:

FindthevalString(CString str) : m_LinkManEmail(str) {};

bool operator() (const strTmpLinkMan &t) const

{

return m_LinkManEmail == t.TmpLinkManeEmail;

}

private:

CString m_LinkManEmail;

};

typedef struct strTmpGroup

{

strTmpGroup()

{

pList = NULL;

}

CString strTmpGroupName;

CListUIEx* pList;

TmpLinkMan_t strTmpLinkList;

}strTmpGroup;


typedef std::list<strTmpGroup> strTmpGroupList_t;

typedef std::list<strTmpGroup>::iterator strTmpGroupIter_t;


class Findtheval

{

//STL查找CListUIEx* pList是否含有

public:

Findtheval(CListUIEx* x) : m_age(x) {};

bool operator() (const strTmpGroup &t) const

{

return m_age == t.pList;

}

private:

CListUIEx* m_age;

};



typedef struct stGroupUser_t

{

stGroupUser_t()

{

pTmpGroupList = NULL;

}

strTmpGroupList_t* pTmpGroupList;

}stGroupUser_t;


extern stGroupUser_t g_stTmpGroupInfo;


std::list<strTmpGroup>::iterator finded_pList = find_if(g_stTmpGroupInfo.pTmpGroupList->begin(), g_stTmpGroupInfo.pTmpGroupList->end(), Findtheval(pRightList));

if (finded_pList != g_stTmpGroupInfo.pTmpGroupList->end())

{

    //找到

    //查找是否有相同String LinkmanEmail

    std::list<strTmpLinkMan>::iterator finded_String = find_if(iterTmpGroupInfo->strTmpLinkList.begin(), iterTmpGroupInfo->strTmpLinkList.end(), FindthevalString(stTmpLinkMan.TmpLinkManeEmail));

if (finded_String == iterTmpGroupInfo->strTmpLinkList.end())

{

   //没有查找到

}

}

STL list 使用find_if查找算法

标签:public   return   

原文地址:http://evely.blog.51cto.com/1089422/1637990

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!