#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. 爬虫如何发现更多的url呢,怎么动态收集新的url连接

    大家在做爬虫采集数据的时候很多都会遇到增量采集的问题,有些时候是通过过滤url来进行的,有些是通过爬取网页后再进行分析判断, 以上这些过程也许大部分做爬虫的都会这么做,各位有没有想过, 除了以上的常用 ...

  2. PAT Advanced 1140 Look-and-say Sequence (20 分)

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

  3. java学习笔记14-多态

    多态可以理解为同一个操作在不同对象上会有不同的表现 比如在谷歌浏览器上按F1会弹出谷歌的帮助页面.在windows桌面按F1会弹出windows的帮助页面. 多态存在的三个必要条件: 继承 重写 父类 ...

  4. Python3+Appium学习笔记05-报错及解决方法

    记录一下使用期间各种报错和解决方法,毕竟搜了半天才找到解决方法.另外提示一下.优先看官方文档. 报错前面都是一样,就是说在处理的时候,服务器发生了一个未知的错误.然后才是具体报错信息 1)seleni ...

  5. win服务器 解决apache 80端口被占用问题

    是系统的服务占用了80端口,所以要么结束系统服务,要么修改apache端口. PID4的服务是World Wide Web Publishing Service 这里选择结束这个系统服务,运行serv ...

  6. 验证码输入自动聚焦下一个input或者删除自动聚焦上一个input

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 洛谷1546 最短网络Agri-Net【最小生成树】【prim】

    [内含最小生成树Prim模板] 题目:https://www.luogu.org/problemnew/show/P1546 题意:给定一个邻接矩阵.求最小生成树. 思路:点少边多用Prim. Pri ...

  8. PHP mysqli_connect_errno() 函数

    返回上一次连接错误的错误代码: <?php $con=mysqli_connect("localhost","wrong_user","my_p ...

  9. 01 | 基础架构:一条SQL查询语句是如何执行的?

    这是专栏的第一篇文章,我想来跟你聊聊MySQL的基础架构.我们经常说,看一个事儿千万不要直接陷入细节里,你应该先鸟瞰其全貌,这样能够帮助你从高维度理解问题.同样,对于MySQL的学习也是这样.平时我们 ...

  10. 安装包设计-------打包(MFC)---------知识总结

    目录: 1.选择文件夹 2.判断文件夹或文件是否存在 3.通过cmd命令行向程序中传递参数. 4.路径处理 5.文件夹以及文件的删除 6.复制文件 7.创建目录 8.从当前的应用程序中抽取资源 9.引 ...