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 ;
}

最新文章

  1. Python标准模块--Iterators和Generators
  2. tornado上手
  3. elasticsearch按照配置时遇到的一些坑 [Failed to load settings from [elasticsearch.yml]]
  4. AC自动机模板
  5. Android View 如何测量
  6. Struct2提交表单数据到Acion
  7. Node.js 参考学习地址
  8. 4.7 《硬啃设计模式》 第24章 麻烦的多角关系 - 中介者模式(Mediator Pattern)简介
  9. 基于服务的SOA架构_后续篇
  10. js 获取url链接的任意参数
  11. [HAOI2007]分割矩阵
  12. (二)php的常量和变量
  13. 【托业】【怪兽】TEST04
  14. JS_高程2.在HTML中使用Javascript(1)
  15. -bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory
  16. Python之路,第五篇:Python入门与基础5
  17. Address already in use: JVM_Bind 端口被占用的几个解决办法
  18. 简单全局HOOK拦截大部分键盘消息
  19. 【uoj428】普通的计数题
  20. 文本挖掘之文本聚类(DBSCAN)

热门文章

  1. java中的redis常用操作
  2. php实用正则
  3. PAT 1029 Median (25分) 有序数组合并与防坑指南
  4. 深入理解JS:执行上下文中的this(二)
  5. lin-cms-dotnetcore.是如何方法级别的权限控制的?
  6. [JavaWeb基础] 006.Struts1的配置和简单使用
  7. Linux题目
  8. AUTOSAR-软件规范文档阅读
  9. js规则和运算符
  10. Java实现 洛谷 P1049 装箱问题