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 ...
随机推荐
- 使用java向邮箱发送邮件
这是我很早之前写的一个工具类,最近在整理自己所学的东西,无意中找到了,就拿出来与大家分享,代码如下: import java.io.ByteArrayOutputStream; import java ...
- NOIp模拟赛二十九
又是受虐的一天呢~接下来四天都要打模拟赛QAQ 今日分数:0(100)+100+0=100 A题O(读入)结论题判断结果时没return 0被subtask卡成0分,喜提fstQAQ,B题DP,C题不 ...
- jquery 取页面中ifram中得节点
<iframe src="html/bai.jsp" frameBorder=0 id=middle name=middle scrolling="yes" ...
- 链表(list)--c实现
做c的开发有1年多了,期间写过c++,感觉基础不够好,补上去,不丢人.o(^▽^)o to better myself. #include <stdio.h> #include <s ...
- Python学习第一天-编写登陆接口
编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 帐号文件user.txt内容如下: qaz 123qwe 12345qweqwr 12321424...... 锁文件user_l ...
- [JAVA · 0基础]:3.转义字符
定义 全部的ASCII码都能够用"\"加数字(通常是8进制数字)来表示.而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\ ...
- 如何在阿里云服务器里配置iis 搭建web服务
IIS,互联网信息服务,一种Web服务组件,利用它,我们可以打开asp.php这些搭建网页所用的文件. 工具/原料 域名 服务器 方法/步骤 登录服务器. 点击开始—>服务器 ...
- BZOJ4259: 残缺的字符串 & BZOJ4503: 两个串
[传送门:BZOJ4259&BZOJ4503] 简要题意: 给出两个字符串,第一个串长度为m,第二个串长度为n,字符串中如果有*字符,则代表当前位置可以匹配任何字符 求出第一个字符串在第二个字 ...
- 基于UDP的DDos反射放大攻击
转自:https://www.us-cert.gov/ncas/alerts/TA14-017A Protocol Bandwidth Amplification Factor DNS 28 to 5 ...
- go语言中在变量后加上接口是什么意思?
如题刚刚开始学习go 语言有些不懂: a.Data = make(map[string]interface{}) 我认为它是在申请a.Data map为字符串类型的空间,那么它后面接一个空的inter ...