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()
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; }
相关文章推荐
- C++ STL 算法:查找算法(6) binary_search、includes
- c++之STL(13) STL 算法 - 查找算法(4)find_first_of(b,e,sb,se) find_first_of(b,e,sb,se,bp)
- c++之STL(13) STL 算法 - 查找算法(2)search_n() search_n(b, e, c, v) search_n(b, e, c, v, p)
- c++之STL(13) STL 算法 - 查找算法(3)search() find_end()
- STL_算法_查找算法(binary_search、includes)
- STL_算法_查找算法(binary_search、includes)
- c++之STL(13) STL 算法 - 查找算法(7)lower_bound() upper_bound() equal_range(0
- C++的STL的binary_search()和includes()
- c++之STL(13) STL 算法 - 查找算法(1)
- C++ STL 算法:查找算法(2) search_n
- c++之STL(13) STL 算法 - 查找算法(5)adjacent_find(b,e) adjacent_find(b,e,p)
- STL中的二分查找算法(binary_search lower_bound upper_bound equal_range)
- STL 源代码分析 算法 stl_algo.h -- binary_search
- C++ STL 算法:查找算法(5) vadjacent_find
- C++标准库---已序区间算法之一binary_search()&includes()
- STL泛型算法--binary_search()
- STL_算法_查找算法(search、find_end)
- C++ STL 算法:查找算法(4)find_first_of
- STL中查找方法用法总结-adjacent_find, binary_search, includes, lower_bound, upper_bound, equal_range
- STL 源码剖析 算法 stl_algo.h -- binary_search