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的更多相关文章

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

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

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

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

  3. 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) ...

  4. cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition

    cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition random_shuffle()//重排,随机重排,打乱顺序 partition()分区,把 ...

  5. cb47a_c++_STL_算法_排列组合next_prev_permutation

    cb47a_c++_STL_算法_排列组合next_prev_permutation 使用前必须先排序.必须是 1,2,3或者3,2,1.否者结果不准确.如果, 1,2,4,6.这样数据不会准确nex ...

  6. cb46a_c++_STL_算法_逆转和旋转reverse_rotate函数advance

    cb46a_c++_STL_算法_逆转和旋转reverse_rotateSTL算法--变序性算法reverse() 逆转reverse_copy()一边复制一般逆转rotate()旋转,某个位置开始前 ...

  7. cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据

    cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据unique(b,e),删除连续性的,删除重复的数据,比如如果有两个连续的5,5,则留下一个.uniqu ...

  8. cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if

    cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if remove_copy()//在复制过程中删除一些数据remove_copy_if() 删除性算法: ...

  9. cb43a_c++_STL_算法_删除_(1)remove_remove_if

    cb43a_c++_STL_算法_删除_(1)remove_remove_ifremove()remove_if() 注意:1.并不是真正的删除,而是把后面的元素向前移动,覆盖被删除元素,元素个数并没 ...

随机推荐

  1. sqoop-介绍及安装

    1.sqoop概述 sqoop是Apache旗下一款hadoop和关系数据库服务器之间传送数据的工具: 核心的功能: 导入,迁入(从关系型数据库-->hdfs hive hbase) 导出,迁出 ...

  2. JS轮播图带序号小点和左右按钮

    轮播图作为前端比较简易的动画,使用非常频繁,这里记录以便使用 此轮播图为最简易自动播放,非无缝,但有按钮,有序号跳转小点 想看全套轮播图可以查看我的分类轮播图全套 html布局 <div sty ...

  3. 利用pandas进行数据子集的获取

  4. [COCOS2DX-LUA]0-005.cocos2dx中关于全面屏和折叠屏的适配的一些见解

    1.随着科技的发展,我们可以看到从iphoneX的刘海屏开始,引发了各种全面屏和异形屏的出现.这是科技的进步,但是对于各大的应用厂商来说,苦不堪言. 2.当然 ,吐槽归吐槽,我们还是要理智的去对待这个 ...

  5. 前端基础知识之html和css全解

    前端回顾 目录 前端回顾 基础知识 HTTP协议 认识HTML HTML组成 HTML标签 div和span标签 特殊的属性 常用标签 认识css 选择器 属性 前端就是展示给用户并且与用户进行交互的 ...

  6. MySQL 可重复读,差点就我背上了一个 P0 事故!

    小黑黑的碎碎念 哎,最近有点忙,备考复习不利,明天还要搬家,好难啊!! 本想着这周鸽了,但是想想还是不行,爬起来,更新一下,周更可不能断.偷懒一下,修改一下之前的一篇历史文章,重新发布一下. P0 事 ...

  7. jchdl - GSL实例 - Counter

    https://mp.weixin.qq.com/s/BjQtQE8DfaKP1XwcTiCwVg   ​​ 摘自康华光<电子技术基础 · 数字部分>(第五版)   参考链接 https: ...

  8. Chisel3 - 运算符和位宽推断

    https://mp.weixin.qq.com/s/rI-CJM6GyI6EUHPZ3uYiFg   如同Verilog中的众多运算符,Chisel也针对自身的数据类型,提供了很多运算符.   Ch ...

  9. 总结了一下css的部分基础知识点。---css学习笔记01

    一. css基础 1. 什么是css 层叠样式表:层叠 2. css的三种使用方式 style 属性 --> <div style="css属性值"></d ...

  10. 【Springboot HBase】遇到的一些问题

    想要运行的代码需要在application中运行 使用@Component并实现CommandLineRunner接口.重写方法@Override run( ) @Component public c ...