查找算法6

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

using namespace std;

int main()
{
	list<int> ilist;
	vector<int> search;

	for (int i = 0; i <= 9; ++i)
		ilist.push_back(i);

	search.push_back(2);
	search.push_back(4);
	search.push_back(6);

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

	if (binary_search(ilist.begin(), ilist.end(), 5))   // binary_search 是查找一个数是不是存在,返回值是一个bool值,binary_search必须要排序。
		cout << "找到了," << endl;
	else
		cout << "没有找到," << endl;

	if (includes(ilist.begin(), ilist.end(), search.begin(), search.end())) // includes是从函数search里边查找,可以是不连续的, includes必须要排序。
		cout << "都有,都找到了," << endl;
	else
		cout << "没有找到," << endl;

	return 0;
}

你可能感兴趣的:(查找算法6)