STL_算法_局部排序(partial_sort、partial_sort_copy)
发布日期:2021-10-22 18:11:18 浏览次数:5 分类:技术文章

本文共 3702 字,大约阅读时间需要 12 分钟。

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)
*****************************************/
/**----------------------------------------------------------------------------------
STL算法---排序算法
sort()                  make_heap()
stable_sort()           push_heap()
partial_sort()          pop_heap()
partial_sort_copy()     sort_heap()
nth_element()
partition()
stable_partition()
----------------------------------------------------------------------------------**/

/**------http://blog.csdn.net/u010579068------**/#include
#include
#include
#include
#include
#include
#include
using namespace std;/*****************************************//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)*****************************************//**----------------------------------------------------------------------------------STL算法---排序算法sort() make_heap()stable_sort() push_heap()partial_sort() pop_heap()partial_sort_copy() sort_heap()nth_element()partition()stable_partition()----------------------------------------------------------------------------------**//*************************************************************************************std::partial_sort 全部排序容器适用 algorithm--------------------------------------------------------------------------------------template
void partial_sort ( RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last );template
void partial_sort ( RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp );//eg:*************************************************************************************//*************************************************************************************std::partial_sort_copy 全部排序容器适用 algorithm--------------------------------------------------------------------------------------template
RandomAccessIterator partial_sort_copy ( InputIterator first,InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last );template
RandomAccessIterator partial_sort_copy ( InputIterator first,InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp );//eg:*************************************************************************************/bool myfunction (int i,int j){ return (i
void Print(T& V){ typename T::iterator iter=V.begin(); while(iter != V.end()) { cout<<*iter++<<" "; } cout<
myvector (myints, myints+9);// vector
::iterator it; // using default comparison (operator <): partial_sort (myvector.begin(), myvector.begin()+5, myvector.end()); cout << "myvector contains:"; Print(myvector); deque
mydeque(myints,myints+9); // using function as comp partial_sort (mydeque.begin(), mydeque.begin()+5, mydeque.end(),myfunction); // print out content: cout << "mydeque contains:"; Print(mydeque);// for (it=myvector.begin(); it!=myvector.end(); ++it)// cout << " " << *it; cout << endl; /**--------------------------------------------------------------------------**/ vector
vec (5); deque
deq (5); // using default comparison (operator <): partial_sort_copy (myints, myints+9, vec.begin(), vec.end()); cout << "myvector contains:"; Print(vec); // using function as comp partial_sort_copy (myints, myints+9, deq.begin(), deq.end(), myfunction); // print out content: cout << "mydeque contains:"; Print(deq);// for (it=myvector.begin(); it!=myvector.end(); ++it)// cout << " " << *it; cout << endl; return 0;}

转载于:https://www.cnblogs.com/jhcelue/p/7040125.html

转载地址:https://blog.csdn.net/weixin_30402343/article/details/94822333 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:浅谈PHP数据库类的构造
下一篇:Appium AndroidKeyCode

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年03月12日 15时27分45秒