C++ STL 排序
#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 排序的更多相关文章
- 详细解说 STL 排序(Sort)
0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...
- 转:详细解说 STL 排序(Sort)
详细解说 STL 排序(Sort) 详细解说 STL 排序(Sort) 作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1. ...
- 详细解说 STL 排序(Sort)(转)
作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1.1 所有sort算法介绍 1.2 sort 中的比较函数 1.3 sor ...
- STL 排序(转载)
这篇文章关于STL中的排序写的虽不深入,但是还是挺好的. 1.sort sort有两种形式,第一种形式有两个迭代器参数,构成一个前开后闭的区间,按照元素的 less 关系排序:第二种形式多加一个指定排 ...
- HDU-1263(STL+排序)
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- Codeforces 997D(STL+排序)
D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...
- (C++)STL排序函数sort和qsort的用法与区别
主要内容: 1.qsort的用法 2.sort的用法 3.qsort和sort的区别 qsort的用法: 原 型: void qsort(void *base, int nelem, int widt ...
- c++STL排序算法注意事项
关于算法中的比较函数 #include<iostream> #include<algorithm> using namespace std; int compare(doubl ...
- 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 ...
- STL排序和检索
//参考书是刘汝佳的那本算法书P108 //sort的用法也就是本来是从小到大排序,如果想要从大到小,中间写一个比较函数就可以了: //以下两个检索的东西 //lower_bound找到一个值的最小插 ...
随机推荐
- 19C imp 导入合并表空间
因为项目需要从9i 导数据到18C,所以发现如下特性 1.18C imp 导入数据,如果表空间在目标库没有,会将表导入到用户默认表空间 2.18C imp 导入数据,如果表空间在目标库有,但缺少权限. ...
- C语言计算两个日期间隔天数
在网上看到了一个C语言计算日期间隔的方法,咋一看很高深,仔细看更高神,很巧妙. 先直接代码吧 #include <stdio.h> #include <stdlib.h> in ...
- maven常用命令参数
整理了一些maven常用命令参数,以便参考:参考了maven官网和网上其他一些maven追随者的文件,不在此一一列举,但表示感谢! mvn命令参数 mvn -v, --version 显示版本信息; ...
- HDU - 6242 Geometry Problem (几何,思维,随机)
Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...
- Windows Media Player播放视频导致程序闪退
在有的电脑上发现,使用Windows Media Player组件播放视频导致程序闪退. 发现是显卡问题,独立显卡换成集成显卡 解决: 打开显卡控制面板->管理3D设置->集成图形-> ...
- uni-app之tabBar的自己配置
1.因为产品相关的的权限,需要配置不同的导航,这时候需要自定义导航.分离出来的就是一个小的组件.(tabBar.vue) 此处暂时用的html插入的代码,能粘贴到vue文件即可. <templa ...
- linux基础知识和常用命令
1.修改主机名 切换到root,然后执行 vim /etc/sysconfig/network,进入其中,更改hostname即可.insert进入修改,esc+:,wq保存退出. 2.用户切换 普通 ...
- eclipse 编辑器 setDirty方法无效
可能是因为使用的编辑器继承了FormPage导致的,在setDirty方法里面多加一行getManagedForm().dirtyStateChanged();就可以了.
- python 改变函数实参的值
def change(n): n[] = 'Mr Gumby' names = ['Mrs Entity', 'Mrs. Thing'] change(names) print(names) resu ...
- pymysql基本使用
导入模块 import pymysql 连接(看一下password有没有,没有的话会怎么样,有很多参数,有些参数也是可以不传的) conn = pymysql.connect(user = &quo ...