vector的查找

vector由于key是顺序增长的整数,所以无法提供高效的按value查找的函数。使用vector进行查找时,要借助find.

vector<int>::iterator p;

p=find(v.begin(),v.end(),a);

if(p!=v.end()) cout<<"we find the number: "<<*p<<endl;

else cout<<"can not find"<<endl;

find可用于其它任何的查找:

int array[10]={10,20,30,40};

int *pp=find(array,array+4,20);

cout<<*pp<<endl;

原文:

http://blog.sina.com.cn/s/blog_6b11cf74010146j8.html

原文地址:https://www.cnblogs.com/mydomain/p/2992683.html