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<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
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 <class RandomAccessIterator>
void partial_sort ( RandomAccessIterator first, RandomAccessIterator middle,
RandomAccessIterator last ); template <class RandomAccessIterator, class Compare>
void partial_sort ( RandomAccessIterator first, RandomAccessIterator middle,
RandomAccessIterator last, Compare comp );
//eg: *************************************************************************************/ /*************************************************************************************
std::partial_sort_copy 全部排序容器适用 algorithm
--------------------------------------------------------------------------------------
template <class InputIterator, class RandomAccessIterator>
RandomAccessIterator
partial_sort_copy ( InputIterator first,InputIterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last ); template <class InputIterator, class RandomAccessIterator, class Compare>
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<j);
}
template <typename T>
void Print(T& V)
{
typename T::iterator iter=V.begin();
while(iter != V.end())
{
cout<<*iter++<<" ";
}
cout<<endl;
}
int main ()
{
int myints[] = {7,6,9,4,1,5,8,2,3};
vector<int> myvector (myints, myints+9);
// vector<int>::iterator it; // using default comparison (operator <):
partial_sort (myvector.begin(), myvector.begin()+5, myvector.end());
cout << "myvector contains:";
Print(myvector); deque<int> 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<int> vec (5);
deque <int> 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;
}

STL_算法_局部排序(partial_sort、partial_sort_copy)的更多相关文章

  1. cb50a_c++_STL_算法_局部排序partial_sort

    cb50a_c++_STL_算法_局部排序partial_sort partial_sort(b,se,e)排序一部分,begin,source end,endcout << " ...

  2. STL_算法_依据第n个元素排序(nth_element)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...

  3. STL_算法_对全部元素排序(sort、stable_sort)

    C++ Primer 学习中. . .   简单记录下我的学习过程 (代码为主) //大部分容器适用.不适用于list容器 sort(b,e) sort(b,e,p) stable_sort(b,e) ...

  4. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  5. STL_算法_逆转(reverse,reverse_copy)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 reverse(b,e)        //逆转区间数据 reverse_copy(b,e,b2) /** ...

  6. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

  7. STL_算法_中使用的函数对象

    写在前面: STL算法中的 函数对象的功能: (1).都是提供一种比较的函数,比较相邻的左右两个值的 相等/大小 等的关系, (2).返回值都是bool :该返回值 貌似是指明 遍历元素是否还要继续往 ...

  8. STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 equal(b,e,b2)       //用来比較第一个容器[b,e)和第二个容器b2开头,是否相等 e ...

  9. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

随机推荐

  1. Linux重新命名文件夹

    linux 重命名文件和文件夹   linux下重命名文件或文件夹的命令mv既可以重命名,又可以移动文件或文件夹. 例子:将目录A重命名为B mv A B 例子:将/a目录移动到/b下,并重命名为c ...

  2. COGS——T 826. [Tyvj Feb11] GF打dota

    http://www.cogs.pro/cogs/problem/problem.php?pid=826 ★★☆   输入文件:dota.in   输出文件:dota.out   简单对比时间限制:1 ...

  3. 实验了一下对于struct引用的成员的改动

    今天写代码的时候,不确定struct用引用传递给函数的时候,他的成员在函数里面改变的时候,是否能影响到外面. 实验了一下 #include <stdio.h> #include <s ...

  4. 【Mockplus视频教程】《10分钟玩转Mockplus》

    地址:http://doc.mockplus.cn/?p=152

  5. NGUI研究之开发项目的一些使用心得比較细节

     不知不觉使用NGI插件已经有一段时间了.感觉NGUI真的是眼下Unity3D中最好用的UI插件. 可是它也有一些不是BUG的BUG,这些问题可能会让新人摸不着头脑,那么这篇文章将总结一下这段时间 ...

  6. node06---npm、silly-datetime、路径问题

    我们刚才学习了,模块就是一些功能的封装,所以一些成熟的.经常使用的功能,都有人封装成为了模块.并且放到了社区中,供人免费下载. 这个伟大的社区,叫做npm. 也是一个工具名字 node package ...

  7. invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

    Column 'dbo.tbm_vie_View.ViewID' is invalid in the select list because it is not contained in either ...

  8. sklearn 词袋 CountVectorizer

    from sklearn.feature_extraction.text import CountVectorizer texts=["dog cat fish","do ...

  9. MinGW - 安装和配置 / MinGW - Howto Install And Configure

    MinGW在线安装程序下载地址:http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get- ...

  10. 微信小程序领取卡券

    微信小程序领取卡券 标签(空格分隔): php 开发前需要准备的工作 1 小程序和公众号要有绑定 2 小程序和该公众号要绑定到同一个开发平台下 [https://open.weixin.qq.com/ ...