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

已序查找算法之  ----------

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;
}


posted @ 2015-03-04 15:38  SandKing  阅读(6)  评论(0)    收藏  举报  来源