STL_算法_局部排序(partial_sort、partial_sort_copy)
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)的更多相关文章
- cb50a_c++_STL_算法_局部排序partial_sort
cb50a_c++_STL_算法_局部排序partial_sort partial_sort(b,se,e)排序一部分,begin,source end,endcout << " ...
- STL_算法_依据第n个元素排序(nth_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...
- STL_算法_对全部元素排序(sort、stable_sort)
C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) //大部分容器适用.不适用于list容器 sort(b,e) sort(b,e,p) stable_sort(b,e) ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_逆转(reverse,reverse_copy)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 reverse(b,e) //逆转区间数据 reverse_copy(b,e,b2) /** ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
- STL_算法_中使用的函数对象
写在前面: STL算法中的 函数对象的功能: (1).都是提供一种比较的函数,比较相邻的左右两个值的 相等/大小 等的关系, (2).返回值都是bool :该返回值 貌似是指明 遍历元素是否还要继续往 ...
- STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 equal(b,e,b2) //用来比較第一个容器[b,e)和第二个容器b2开头,是否相等 e ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...
随机推荐
- HDU Integer's Power(容斥原理)
题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后 ...
- centos 7.1安装frees witch
http://blog.sina.com.cn/s/blog_539d6e0c0102zgvm.html
- /etc/rsyncd.conf
[root@backup ~]# cat /etc/rsyncd.conf #Rsync server#created by oldboy ##rsyncd.conf start##uid = rsy ...
- DataTable 数据导入MS ACCESS 数据库中 数字类型字段为空的解决办法
string strSql = "insert into GongCheng (GCSY,GCBH,GCBHOLD,GCMC,GCKCJD,GCJSDW,GCSJDW,GCKCDW,GCSG ...
- 最快的方式清除Chrome浏览器DNS缓存
最快的方式就是直接数据url,然后清除不须要的dns缓存. chrome://net-internals/#dns 一般步骤.要经过下列几项. Chrome - > 扳手 - > 选项 - ...
- php中file_get_contents如何读取大容量文件
php中file_get_contents如何读取大容量文件 一.总结 一句话总结:使用file_get_contents()进行分段读取,file_get_contents()函数可以分段读取 1. ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(1)
当您在使用大规模的设施工作,可能有时候,您必须处理许多并发打开的连接.没有人会使用十台服务器来为两个并发用户提供服务--在许多情况下,这根本没有意义.大量的设施通常会处理成百上千的并发连接.引入连接池 ...
- 《剑指offer》跳台阶
一.题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.输入描述 输入n级台阶 三.输出描述 输出总有多少种不同跳法 四.牛客网提供的框架 cla ...
- ES6中includes、startsWith、endsWith
es6新增includes:返回布尔值,表示是否找到字符串.startsWith:返回布尔值,表示字符串是否在源字符串的头部位置.endsWith:返回布尔值,表示参数字符串是否在源字符串尾部. va ...
- UVa 1001 Say Cheese【floyd】
题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置, 在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 看到n<=100,又是求最短时间,想到 ...