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. sql拼接

    with t as( select 'Charles' parent, 'William' child union select 'Charles', 'Harry' union select 'An ...

  2. 多任务-进程之Queue的进程间通信

    1.经过线程和进程的对比,不难的知道,线程和进程有相当大的区别,如全局变量资源不能够共享. 2.在不同的进程间,如何实现通信呢? 需要提及的一个概念就是Queue,它是一个消息队列,下面通过一个例子来 ...

  3. ubuntu 装tensorflow出现 conda install ERROR missing write permission错误

    通过搜索tensorflow然后运行,例如:$ conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflo ...

  4. PHP中比较有用的几个函数

    php_check_syntax 这个函数可以用来检查特定文件中的PHP语法是否正确. highlight_string 当你想要把PHP代码显示到页面上时,highlight_string()函数就 ...

  5. swoole之memoryGlobal内存池分析

    内存池的作用: 直接使用系统调用malloc会有如下弊端: 频繁分配内存时会产生大量内存碎片 频繁分配内存增加系统调用开销 容易造成内存泄漏 内存池是预先申请一定数量的,大小相等的内存块作为预备使用: ...

  6. vuex 基本入门和使用(三)-关于 mutation

    vuex 基本入门和使用(三)-关于 mutation vuex 版本为^2.3.1,按照我自己的理解来整理vuex. 关于 mutation 这里应该很好理解. 更改 Vuex 的 store 中的 ...

  7. ASP.NET-本地化、全球化

    在<system.web>中加入一个全球化的标识,网站就可以自适应全球化了 也可以将出错信息全球化 上面的这种方式测试过对google浏览器好像没用,但是对IE内核的是可行的,可能goog ...

  8. max带来的冲突

    题目要求: /* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名:sum123.cpp * 作 者:林海云 * 完毕日期:20 ...

  9. Android面试精华

    SIM卡的EF文件有什么作用? SIM卡里的全部文件按树来组织: 主文件MF(Master File)--主文件仅仅有文件头,里面存放着整个SIM卡的控制和管理信息 专用文件DF(Dedicated ...

  10. 图文介绍MyEclipse (2015) 中创建简单的Maven项目的步骤(用于生成可运行jar文件)

    利用MyEclipse的引导,能够非常方便的创建简单的.用于生成可运行jar文件的Maven项目: (原创文章,转载请注明转自Clement-Xu的博客:http://blog.csdn.net/cl ...