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

  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
------------------------------
请按任意键继续. . .

C++ STL 排序的更多相关文章

  1. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  2. 转:详细解说 STL 排序(Sort)

    详细解说 STL 排序(Sort) 详细解说 STL 排序(Sort) 作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1. ...

  3. 详细解说 STL 排序(Sort)(转)

    作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1.1 所有sort算法介绍 1.2 sort 中的比较函数 1.3 sor ...

  4. STL 排序(转载)

    这篇文章关于STL中的排序写的虽不深入,但是还是挺好的. 1.sort sort有两种形式,第一种形式有两个迭代器参数,构成一个前开后闭的区间,按照元素的 less 关系排序:第二种形式多加一个指定排 ...

  5. HDU-1263(STL+排序)

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  6. Codeforces 997D(STL+排序)

    D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...

  7. (C++)STL排序函数sort和qsort的用法与区别

    主要内容: 1.qsort的用法 2.sort的用法 3.qsort和sort的区别 qsort的用法: 原 型: void qsort(void *base, int nelem, int widt ...

  8. c++STL排序算法注意事项

    关于算法中的比较函数 #include<iostream> #include<algorithm> using namespace std; int compare(doubl ...

  9. AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)

    A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  10. STL排序和检索

    //参考书是刘汝佳的那本算法书P108 //sort的用法也就是本来是从小到大排序,如果想要从大到小,中间写一个比较函数就可以了: //以下两个检索的东西 //lower_bound找到一个值的最小插 ...

随机推荐

  1. 03 WIndows编程——手绘函数调用过程

    源码 #include<Windows.h> #include<stdio.h> int MessageBoxPrint(char *szFormat, ...); int W ...

  2. No PostCSS Config found in报错解决

    前情提要]日前本人将本地项目上传GitHub之后,然后再clone到本地,运行是报错:Error: No PostCSS Config found in... 项目在本地打包运行的时候不报错,上传到 ...

  3. Python基本语法变量

    Python的语法和其它编程语言的语法有所不同,编写Paython程序之前需要对语法有所了解,才能编写规范的Python程序.本篇介绍Python标识符的同时,也讨论了Python变量的声明和赋值.通 ...

  4. linux下18种监测网络带宽方式

    1. nload nload是一个命令行工具,让用户可以分开来监控入站流量和出站流量.它还可以绘制图表以显示入站流量和出站流量,视图比例可以调整.用起来很简单,不支持许多选项. 所以,如果你只需要快速 ...

  5. linux服务器日志剖析

    常规tomcat,apache,nginx,错误日志,还有项目log4j日志 tomcat (以tomcat7.082为例) tomcat日志配置 运行日志和访问日志结合在一起,先说下日志哪边配置,在 ...

  6. Maven如何上传ja包到远程仓库

    本文转载自沧海一屌丝的博客 https://blog.csdn.net/qq_31924435/article/details/53745811 mvn install  会将项目生成的构件安装到本地 ...

  7. list 对像排序

    在C#的List操作中,针对List对象集合的排序我们可以使用OrderBy.OrderByDescending.ThenBy.ThenByDescending等方法按照特定的对象属性进行排序,其中O ...

  8. python中的几种数据类型(一)

    一.整型(数字)      python2中有长整形long      python3 中全都是整型 int n = 56 print(n.bit_length()) # 0011 1000 # 12 ...

  9. 2019牛客多校D move——乱搞&&思维题

    题意 给定 $n$ 个物品,体积分别为 $v_i$,现有 $K$ 的容积一样的箱子,按如下策略装入物品:每次选取尽可能大的装入(较大的不能装入时可以向小的找),依次装入箱子. 分析 首先,不具有严格的 ...

  10. bootstrap的css和js

    css:<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel=" ...