#include<iostream>
#include<map>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
const int n=100000;
class Map//优势:排序
{
private:
map<int,int>a;//第一个int不能重复
map<int,int>::iterator p;//第一个int不能重复
public:
Map()
{
srand(time(0));
for(int i=0;i<n;++i)
{
a.insert(pair<int,int>(i,rand()%n));
}
}
void browse()
{
for(p=a.begin();p!=a.end();++p)
{
cout<<p->first<<"-"<<p->second<<endl;
}
}
void find_m()
{
clock_t t1,t2;
t1=clock();
for(int i=0;i<100000;++i)
{
p=a.find(20);
}
t2=clock();
cout<<t2-t1;
}
};
int main()
{
Map m;
m.find_m();
return 0;
}
C++map容器,优势:查找
最新推荐文章于 2025-07-09 15:31:41 发布