#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <functional>
#include <iterator>

using namespace std;

int main()
{
  deque<int> deq1;
  deque<int>::iterator deq_iter1;

  for (int k=0;k<16;k++)
  {
    deq1.push_back(rand());
  }

  for (deq_iter1 = deq1.begin();deq_iter1 != deq1.end();++deq_iter1)
  {
    cout << *deq_iter1 << " ";
  }
  cout << endl;
  cout << "------------------------------"<<endl;

  nth_element(deq1.begin(), deq1.begin() + 5, deq1.end());
  for (deq_iter1 = deq1.begin(); deq_iter1 != deq1.end(); ++deq_iter1)
  {
    cout << *deq_iter1 << " ";
  }
  cout << endl;
  cout << "------------------------------" << endl;

  
  copy(deq1.begin(), deq1.begin() + 5,ostream_iterator<int>(cout," "));
  cout << endl;
  cout << "------------------------------" << endl;

  nth_element(deq1.begin(), deq1.end() - 5, deq1.end());
  copy(deq1.end() - 5,deq1.end(), ostream_iterator<int>(cout, " "));
  cout << endl;
  cout << "------------------------------" << endl;

  nth_element(deq1.begin(), deq1.begin() + 5,deq1.end(), greater<int>());
  for (deq_iter1 = deq1.begin(); deq_iter1 != deq1.end(); ++deq_iter1)
  {
    cout << *deq_iter1 << " ";
  }
  cout << endl;
  cout << "------------------------------" << endl;

  system("pause");
  return 0;
}

==================================

41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491
------------------------------
41 491 5705 6334 9961 11478 15724 16827 18467 19169 23281 24464 26500 26962 28145 29358
------------------------------
41 491 5705 6334 9961
------------------------------
24464 26500 26962 28145 29358
------------------------------
29358 28145 26962 26500 24464 23281 19169 18467 16827 15724 11478 9961 6334 5705 491 41
------------------------------
请按任意键继续. . .

C++ nth_element greater的更多相关文章

  1. nth_element学习

    今天学习到STL中的nth_element,她是一个默认能求第k小的数的方法,需要的头文件为algorithm. 默认为:nth_element(start, start+n, end) 使第n大元素 ...

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

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

  3. 牛客2018多校第六场 J Heritage of skywalkert - nth_element

    传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...

  4. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  5. cb51a_c++_STL_算法_根据第n个元素排序nth_element

    cb51a_c++_STL_算法_根据第n个元素排序nth_elementnth_element(b,n,e),比如最大的5个数排序,或者最小的几个数nth_element(b,n,e,p)对比:pa ...

  6. nth_element 测试程序

    /******************************************************************** created: 2014/04/29 11:35 file ...

  7. Transform a BST to greater sum tree

    Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater th ...

  8. R.java 文件内报错:Underscores can only be used with source level 1.7 or greater。

    R.java 文件内报错:Underscores can only be used with source level 1.7 or greater 网上查找后得知是Android工程图片资源命名的问 ...

  9. Poj(2407),Greater New York Regional 2015 (D)

    题目链接:http://poj.org/problem?id=2407 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. RHEL7启动到命令模式

    打开/etc/inittab 文件会看到以下信息 从中知道想要启动后就进入完整的多用户文本模式(命令行模式) 以root权限执行: ln -sf /lib/systemd/system/multi-u ...

  2. Ubuntu系统---C++之VScode IDE 编译器安装

    Ubuntu系统---C++之VScode IDE 编译器安装 简单了解了一下VScode,直观印象:安装包很小(不像VS那么大占用十G左右).跨平台.小巧.可以编译C++ / java / pyth ...

  3. Java字节码方法表与属性表深度剖析

    方法表: 在上一次咱们已经分析到了字段信息了,如下: 紧接着就是方法相关的信息了: 而它展开之后的结构为: 所以往后数2个字节,看一下方法的总数: 3个方法,可咱们只定义了两个方法呀: 因为编译器会为 ...

  4. easyui-filebox上传文件或图片时选择相同文件无法触发change事件的问题

    其实很简单,当选择完一个文件之后,会将文件名存放在input中的value值中,当下一次onChange之后,比对玩发现,value值没有发生变化,所以不能触发. 所以,只需要下次将value值清空就 ...

  5. python2和python3编程差异杂谈(-)

    python2 默认编码ascii 在使用中文时要显示的声明   #-*-encoding:utf-8-*- python3 默认编码utf-8,良好的支持了中文输入 python2: print函数 ...

  6. 1、课程简介-Spring 注解驱动开发

    1.课程简介-Spring 注解驱动开发

  7. clip 语法

    clip 语法: clip:auto | <shape> <shape>:rect(<number>|auto <number>|auto <nu ...

  8. HashMap判断键是否为null

    用containsKey(),而不用get(): HashMap中,null可以作为键,这样的键只有一个:可以有一个或多个键所对应的值为null.当get()方法返回null值时,即可以表示HashM ...

  9. MySQL 8.0.15 配置 MGR单主多从

    转载自:http://www.cnblogs.com/zhangzihong/p/10443526.html 一.简介 MySQL Group Replication(简称MGR)字面意思是mysql ...

  10. MySQL5.7 (审计)通过init_connect + binlog 实现MySQL审计功能

    转载自:https://blog.51cto.com/13941177/2173620 一.简介 1.概述 mysql本身已经提供了详细的sql执行记录–general log ,但是开启它有以下几个 ...