c++之STL(13) STL 算法 - 查找算法(6)binary_search(b,e,v) binary_search(b,e,v,p) includes(b,e,sb,se) include

binary_search(b,e,v)

binary_search(b,e,v,p)

includes(b,e,sb,se)

includes(b,e,sb,se,p)

STL 查找算法

find()

find_if()

search_n()

search()

find_end()

find_first_of()

adjacent_find()

已序区间查找算法(先排序,对数复杂度)

binary_search()

includes()

lower_bound()

upper_bound()

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

using namespace std;

//bool doubled(int elem1, int elem2)
//{
//	return elem1 *2 == elem2;
//}

int main()
{
	list<int> ilist;
	vector<int> search;
	for (int i = 1; i <= 9; i++)
	{
		ilist.insert(ilist.end(), i);
	}
	search.push_back(3);
	search.push_back(4);
	search.push_back(7);

	for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); iter++)
	{
		cout << *iter << ' ';
	}
	cout << endl;

	if (binary_search(ilist.begin(), ilist.end(), 5))
		cout << "找到了!" << endl;
	else
		cout << "没找到!" << endl;
	// 找有3,有4,有7
	if (includes(ilist.begin(), ilist.end(), search.begin(), search.end()))
		cout << "都有, 都找到了!" << endl;
	else
		cout << "没有找到!" << endl;

	///*vector<int>::iterator pos;
	//pos = adjacent_find(ivec.begin(), ivec.end());*/

	//if (pos!=ivec.end())
	//{
	//	cout << "找到了!位置:" << distance(ivec.begin(), pos) + 1 << endl;
	//}
	//else
	//	cout << "没找到!";

	//pos = adjacent_find(ivec.begin(), ivec.end(), doubled);
	//if (pos != ivec.end())
	//{
	//	cout << "找到了,位置:"<<distance(ivec.begin(), pos) + 1 << endl;
	//}
	//else
	//	cout << "没找到!" << endl;
	//

	system("pause");
	return 0;
} 

    原文作者:查找算法
    原文地址: https://blog.csdn.net/taotaoah/article/details/52179207
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞