您的位置:首页 > 编程语言 > C语言/C++

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

2016-08-11 07:42 411 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: