`
nuaa_liu
  • 浏览: 25390 次
  • 性别: Icon_minigender_1
  • 来自: 南京
最近访客 更多访客>>
社区版块
存档分类
最新评论

vector&&map

阅读更多

#include <algorithm>
#include <map>
#include <vector>

//std::map在insert后是自动排序的,查找的时候可以使用 find
std::map<int,string> mapDemo_;
if(mapDemo_.find(nKey) != mapDemo_.end())
{
//find
}

//std::vector在push_back()后不会自动排序,可以使用sort进行排序
std:vector(int) vecDemo_;
sort(vecDemo.begin(),vecDemo_.end());
if(binary_search(vecDemo.begin(),vecDemo_.end(),nFindKey))
{
//find
}

//map的key和vector的value必须是重载过比较符的
typedef struct stKeyStrValue
{
   unsigned int nKey;
   string strValue;
   int operator <(const stKeyStrValue &p)const
   {
	return ( this->nKey < p.nKey);
   }

   bool operator==(const unsigned int & nKey)const
   {
	return (this->nKey == nKey);
   }
}SKeyStrValue;

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics