cb50a_c++_STL_算法_局部排序partial_sort partial_sort(b,se,e)排序一部分,begin,source end,endcout << "部分排序,开头的5个数排序" << endl;partial_sort(ideq.begin(), ideq.begin() + 5, ideq.end()); 需要注意的是,不能保持未排序元素的原始顺序.在执行 partial_sort() 后后面元素的顺序是不确定的,这取决于具体的实…
C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) /***************************************** // partial_sort(b,se,e) partial_sort(b,se,e,p) partial_sort_copy(sb,se,db,de) partial_sort_copy(sb,se,db,de,p) *****************************************/ /**-----------…
cb51a_c++_STL_算法_根据第n个元素排序nth_elementnth_element(b,n,e),比如最大的5个数排序,或者最小的几个数nth_element(b,n,e,p)对比:partition()算法,分区算法 error C2675: 一元“++”:“TT88”不定义该运算符或到预定义运算符可接收类型的转换for (TT88::iterator iter = ideq.begin(); iter != ideq.end(); ++ideq),写错了,应该是++iter /…
cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort sort(b,e) sort(b,e,p) stable_sort(b,e) stable_sort(b,e,p) 注意: 不适用于list容器,list有成员函数sort(); cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort sort(b,e) sort(b,e,p) stable_sort(b,e) //stirng,按字符个数排序.能够保证位置间前面一致.比如 22 33…
cb47a_c++_STL_算法_排列组合next_prev_permutation 使用前必须先排序.必须是 1,2,3或者3,2,1.否者结果不准确.如果, 1,2,4,6.这样数据不会准确next_permutation()//原始数据是从小到大的, 1,2,3prev_permutation() //原始数据是从大到小的,比如 3 ,2 ,1,则可以使用这个算法. 3个数字就6种组合.1 2 31 3 22 1 32 3 13 1 2 3 2 1 返回值是ture,则还有下一个组合fal…
*cb36a_c++_STL_算法_区间的比较equal_mismatch_lexicographical_compare 区间:容器中的全部数据或者部分数据,都叫做区间 equal(b,e,b2),比较两个容器数据是不是相等 ,b(容器1,迭代器begin()),e(容器1,迭代器end(),b2(容器2,迭代器2指向的位置,begin2if(equal(ivec.begin(),ivec.end(),ilist.begin())) equal(b,e,b2,p) p,parameter,函数…
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置upper_bound()--查找最后一个可能的位置equal_range()--同时查找第一个和最后一个可能的位置.做了两件事,先做lower_bound(),再upper_bound() pair<list<int>::iterator, list<int>::iterator>…
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e,v),begin,end,value--返回bool,不会告诉具体找到的位置.只能找一个if (binary_search(iset.begin(), iset.end(), 5))//返回boolbinary_search(b,e,v,p) begin,end, value,parameter(…
cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-parameter(谓词),函数,条件,规则.连续的两个符合条件的数据adjacent_find() 算法可以用来搜索序列中两个连续相等的元素.用 == 运算符来比较连续的一对元素,返回的迭代器指向前两个相等元素中的第一个.如果没有一对相等的元素,这个算法返回这个序列的结束迭代器. http://c.bi…
cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);find_if()search_n()search()find_end()find_first_of()adjacent_find()注意:1.如果是已序区间,可以使用已序区间的查找算法(效率高)binary_search()includes()lower_bound()upper_bound()2.关…