您的位置:首页 > 其它

STL算法------查找6(二分查找,包含查找)

2015-03-04 15:38 471 查看
已序查找算法之 ----------

1. binary_search(b, e, v ) --只能找一个; 找到或没找到,不能返回位置

2. binary_search(b, e, v, p )

3. include(b, e, sb, se )

4. include(b, e, sb, se, p )

#include <iostream>
#include <algorithm>
#include <list>
#include <vector>

using namespace std;

int main( int argc, char** argv )
{
list<int> lst;
vector<int> vec;
for( int i = 0; i<10; ++i )
{
lst.insert( lst.end(), i );
}
vec.push_back(1);
vec.insert(vec.end(), 3);
vec.insert(vec.end(), 7);

for(list<int>::const_iterator citr=lst.begin(); citr!=lst.end(); ++citr)
{
cout<<*citr<<' ';
}
cout<<endl;

if( binary_search(lst.begin(), lst.end(), 5) )
{
cout<<"find"<<endl;
}else{
cout<<"not find"<<endl;
}

if( includes( lst.begin(), lst.end(), vec.begin(), vec.end()) )
{
cout<<"find"<<endl;
}else{
cout<<"not find"<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: