c++ algorithm的常用函数

https://blog.csdn.net/hy971216/article/details/80056933

reverse()

reverse(it,it2) 可以将数组指针在[it,it2)之间的元素或容器的迭代器在[it,it2)范围内的元素进行反转。

返回全排列:next_permutation(a,a+3)返回两个位置之间的全排列并原地赋值;

 #include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int a[]={,,};
printf("%d %d %d\n",a[],a[],a[]);
while(next_permutation(a,a+)){
printf("%d %d %d\n",a[],a[],a[]);
}
return ;
}

返回两个位置之间的某个数第一次出现的下标和最后一次的下标:

 #include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int a[]={,,,,,,,,,};
printf("%d,%d\n",int(lower_bound(a,a+,)-a),int(upper_bound(a,a+,)-a));
return ;
}

sort()函数的排序:可以对数组元素和结构体数组排序; 对容器排序只能对vector, string,  deque进行sort()

deque是一种双头容器,参见:https://www.cnblogs.com/LearningTheLoad/p/7450948.html

 #include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int main()
{
vector<int> vi;
vi.push_back();
vi.push_back();
vi.push_back();
sort(vi.begin(),vi.end(),cmp);
for(int i=;i<;i++){
printf("%d ",vi[i]);
}
return ;
}

【c++进阶:c++ algorithm的常用函数】的更多相关文章

  1. mysql进阶(二十九)常用函数

    mysql进阶(二十九)常用函数 一.数学函数 ABS(x) 返回x的绝对值 BIN(x) 返回x的二进制(OCT返回八进制,HEX返回十六进制) CEILING(x) 返回大于x的最小整数值 EXP ...

  2. <algorithm>中常用函数

    先说一下STL操作的区间是 [a, b),左边是闭区间,右边是开区间,这是STL的特性,所以<algorithm>里面的函数操作的区间也都是 [a, b). 先声明一下, sort()函数 ...

  3. go语言之进阶篇字符串操作常用函数介绍

    下面这些函数来自于strings包,这里介绍一些我平常经常用到的函数,更详细的请参考官方的文档. 一.字符串操作常用函数介绍 1.Contains func Contains(s, substr st ...

  4. js进阶 13-6 jquery动画效果相关常用函数有哪些

    js进阶 13-6 jquery动画效果相关常用函数有哪些 一.总结 一句话总结:animate(),stop(),finish(),delat()四个. 1.stop()方法的基本用法是什么(sto ...

  5. STL algorithm 头文件下的常用函数

    algorithm 头文件下的常用函数 1. max(), min()和abs() //max(x,y)和min(x,y)分别返回x和y中的最大值和最小值,且参数必须时两个(可以是浮点数) //返回3 ...

  6. algorithm下的常用函数

    algorithm下的常用函数 max(),min(),abs() max(x,y)返回x和y中最小的数字 min(x,y)返回x和y中最大的数字 abs(x)返回x的绝对值,注意x应当是整数,如果是 ...

  7. matlab进阶:常用功能的实现,常用函数的说明

    常用功能的实现 获取当前脚本所在目录 current_script_dir = fileparts(mfilename('fullpath')); % 结尾不带'/' 常用函数的说明 bsxfun m ...

  8. SQLite进阶-19.常用函数

    目录 SQLite常用函数 SQLite常用函数 SQLite 有许多内置函数用于处理字符串或数字数据. 序号 函数 & 描述 1 SQLite COUNT 函数SQLite COUNT 聚集 ...

  9. 【算法专题】工欲善其事必先利其器—— 常用函数和STL

    一.    常用函数 #include <stdio.h> int getchar( void );               //读取一个字符, 一般用来去掉无用字符 char *ge ...

随机推荐

  1. Host xxx is not allowed to connect to this MariaDb server

    直接复制代码,无需修改 第一:// %:表示从任何主机连接到mysql服务器 GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'pass ...

  2. Android 组件化之路 资源冲突问题

    比如我现在有3个模块:app模块,user模块,me模块,其中app模块依赖user模块和me模块. 然后我在user模块和me模块的strings.xml中都定义了greet字符串: // user ...

  3. redis、rabitmq对比

    redis.rabitmq对比 原文地址 简要介绍 RabbitMQ RabbitMQ是实现AMQP(高级消息队列协议)的消息中间件的一种,最初起源于金融系统,用于在分布式系统中存储转发消息,在易用性 ...

  4. linux下重启tomcat命令

    在Linux系统下,重启Tomcat使用命令操作的! 首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh 查看 ...

  5. 如何代替set get方法

    博主刚刚看其他人的博客的时候,发现好多人还在用 生成set get方法  虽然是自动生成的 但是看起来很复杂,影响代码的可读性 那么有什么办法能代替set  get方法吗? 当然有啦!!! 只需要导入 ...

  6. CodeForces-916A-jamie and Alarm Snooze(笨比题目)

    链接: https://vjudge.net/problem/CodeForces-916A 题意: Jamie loves sleeping. One day, he decides that he ...

  7. spark的accumulator值保存在哪里?

    答案:保存在driver端.因此需要对收集的信息的规模要加以控制,不宜过大.避免 driver端的outofmemory问题!!!

  8. 【leetcode】1200. Minimum Absolute Difference

    题目如下: Given an array of distinct integers arr, find all pairs of elements with the minimum absolute ...

  9. IntelliJ IDEA 2019.3激活破解教程(亲测有效,可激活至 2089 年)

    IntelliJ IDEA 2019.3激活破解教程(亲测有效,可激活至 2089 年) 所有软件安装位置,作者均在无中文.无空格目录下进行操作的 IntelliJ IDEA 2019.3激活破解教程 ...

  10. Linux下lazarus交叉编译 win32[win64]

    环境 vmvare + deepin Linux64 + lazarus2.0.6 参考:https://wiki.freepascal.org/Cross_compiling_for_Win32_u ...