cb51a_c++_STL_算法_根据第n个元素排序nth_element
cb51a_c++_STL_算法_根据第n个元素排序nth_element
nth_element(b,n,e),比如最大的5个数排序,或者最小的几个数
nth_element(b,n,e,p)
对比:partition()算法,分区算法
error C2675: 一元“++”:“TT88”不定义该运算符或到预定义运算符可接收类型的转换
for (TT88::iterator iter = ideq.begin(); iter != ideq.end(); ++ideq),写错了,应该是++iter
/*cb51a_c++_STL_算法_根据第n个元素排序nth_element
nth_element(b,n,e),比如最大的5个数排序,或者最小的几个数
nth_element(b,n,e,p)
对比:partition()算法,分区算法 error C2675: 一元“++”:“TT88”不定义该运算符或到预定义运算符可接收类型的转换
for (TT88::iterator iter = ideq.begin(); iter != ideq.end(); ++ideq),写错了,应该是++iter
*/ #include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <functional> using namespace std; template <class TT88>
void print88(TT88 &ideq)
{
for (TT88::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
cout << *iter << ' ';
cout << endl;
} int main()
{
deque<int> ideq,ideq2;
for (int i = ; i <= ; ++i)
ideq.push_back(i);
for (int i = ; i <= ; ++i)
ideq.push_back(i);
for (int i = ; i <= ; ++i)
ideq.push_back(i);
ideq2 = ideq; print88(ideq);
nth_element(ideq.begin(), ideq.begin() + , ideq.end());//默认less<int>(),升序
cout << "nth_element排序后:" << endl;
print88(ideq); cout << "用copy,到输出流迭代器显示:" << endl;
copy(ideq.begin(), ideq.begin() + , ostream_iterator<int>(cout, " "));
cout << endl; ideq = ideq2;
nth_element(ideq.begin(), ideq.begin() + , ideq.end(),greater<int>());//降序,大到小
cout << "降序:" << endl;
print88(ideq); deque<int>::iterator pos;
//pos = partition(ideq.begin(), ideq.end(), bind2nd(greater<int>(), 3));
cout << endl;
ideq = ideq2;
cout << "分区partition小于等于3放左边,其余放右边" << endl;
pos = partition(ideq.begin(), ideq.end(), bind2nd(less_equal<int>(), ));
print88(ideq);
copy(ideq.begin(), pos, ostream_iterator<int>(cout, " "));
return ;
}
cb51a_c++_STL_算法_根据第n个元素排序nth_element的更多相关文章
- STL_算法_依据第n个元素排序(nth_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...
- cb50a_c++_STL_算法_局部排序partial_sort
cb50a_c++_STL_算法_局部排序partial_sort partial_sort(b,se,e)排序一部分,begin,source end,endcout << " ...
- cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort sort(b,e) sort(b,e,p) stable_sort(b,e) stable_sort(b,e,p) ...
- cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition
cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition random_shuffle()//重排,随机重排,打乱顺序 partition()分区,把 ...
- cb47a_c++_STL_算法_排列组合next_prev_permutation
cb47a_c++_STL_算法_排列组合next_prev_permutation 使用前必须先排序.必须是 1,2,3或者3,2,1.否者结果不准确.如果, 1,2,4,6.这样数据不会准确nex ...
- cb46a_c++_STL_算法_逆转和旋转reverse_rotate函数advance
cb46a_c++_STL_算法_逆转和旋转reverse_rotateSTL算法--变序性算法reverse() 逆转reverse_copy()一边复制一般逆转rotate()旋转,某个位置开始前 ...
- cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据
cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据unique(b,e),删除连续性的,删除重复的数据,比如如果有两个连续的5,5,则留下一个.uniqu ...
- cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if
cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if remove_copy()//在复制过程中删除一些数据remove_copy_if() 删除性算法: ...
- cb43a_c++_STL_算法_删除_(1)remove_remove_if
cb43a_c++_STL_算法_删除_(1)remove_remove_ifremove()remove_if() 注意:1.并不是真正的删除,而是把后面的元素向前移动,覆盖被删除元素,元素个数并没 ...
随机推荐
- Ef core 如何设置主键
在正题之前,先说明几个问题. (1)写 sql 不好吗,为什么要引入 ORM ? 总的来说由于需求的复杂性增加,引入了面向对象编程,进而有了 ORM ,ORM 使得开发人员以对象的方式表达业务逻辑.对 ...
- 关于Dev-C++一种引用头文件<iostream>问题(暴力解决)
问题情况如下,因个人水平有限,不知道具体原因是啥,当引用头文件<iostream>时会出现如下问题,经排查,并不是头文件本身的问题,有可能是Dev哪一个文件被改动了,或者设置出了问题(前者 ...
- DQN(Deep Q-learning)入门教程(五)之DQN介绍
简介 DQN--Deep Q-learning.在上一篇博客DQN(Deep Q-learning)入门教程(四)之Q-learning Play Flappy Bird 中,我们使用Q-Table来 ...
- tmux简单使用
tmux简单使用 Tmux ("Terminal Multiplexer"的简称), 是一款优秀的终端复用软件,类似 GNU screen,但比screen更出色.tmux来自于O ...
- JS实现PC端URL跳转到对应移动端URL
在做移动端网站时,有时因技术问题或其他原因无法制作响应式版面,而移动端页面只能放到子目录下,但是手机端通过搜索引擎进入网站电脑端子页面,无法匹配到移动端页面,使得用户体验很不好,即影响排名也影响转化. ...
- Spring boot Sample 006之spring-boot-custom-servlet
一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.步骤 2.1.点击File -> New Project -> Spring Initializer,点击next 2 ...
- Rocket - regmapper - RegMapper
https://mp.weixin.qq.com/s/aXxgzWwh6unuztjgyVX0iQ 简单介绍RegMapper的实现. 1. 简单介绍 RegMapper使用指定的输入接口,为一组寄存 ...
- Rocket - tilelink - Broadcast
https://mp.weixin.qq.com/s/-pjCLzzincJz0Z66orx8kg 介绍Broadcast的实现. 1. 基本介绍 TLBroadcast实现的是 ...
- (Java实现) 洛谷 P1319 压缩技术
题目描述 设某汉字由N X N的0和1的点阵图案组成,如下图.我们依照以下规则生成压缩码.连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下.第一个数表示连续有几个0 ...
- Java实现 LeetCode 668 乘法表中第k小的数(二分)
668. 乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 ...