c++ stl 获取最小值_如何在C ++ STL中找到向量的最小/最小元素?

c++ stl 获取最小值

Given a vector and we have to minimum/smallest element using C++ STL program.

给定一个向量,我们必须使用C ++ STL程序最小/最小元素。

寻找向量的最小元素 (Finding smallest element of a vector)

To find a smallest or minimum element of a vector, we can use *min_element() function which is defined in <algorithm> header. It accepts a range of iterators from which we have to find the minimum / smallest element and returns the iterator pointing the minimum element between the given range.

找到向量的最小或最小元素 ,我们可以使用在<algorithm>标头中定义的* min_element()函数 。 它接受一定范围的迭代器,我们必须从中查找最小/最小元素,然后返回指向给定范围之间的最小元素的迭代器。

Note: To use vector – include <vector> header, and to use *min_element() function – include <algorithm> header or we can simply use <bits/stdc++.h> header file.

注意:要使用vector –包含<vector>头文件,并使用* min_element()函数 –包含<algorithm>头文件,或者我们可以简单地使用<bits / stdc ++。h>头文件。

Syntax:

句法:

    *min_element(iterator start, iterator end);

Here, iterator start, iterator end are the iterator positions in the vector between them we have to find the minimum value.

在这里, 迭代器开始,迭代器结束是它们之间向量中的迭代器位置,我们必须找到最小值。

Example:

例:

    Input:
vector<int> v1{ 10, 20, 30, 40, 50, 25, 15 };
cout << *min_element(v1.begin(), v1.end()) << endl;
Output:
10

C ++ STL程序查找向量的最小或最小元素 (C++ STL program to find minimum or smallest element of a vector )

//C++ STL program to find minimum or smallest 
//element of a vector 
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
//vector
vector<int> v1{ 10, 20, 30, 40, 50 };
//printing elements
cout << "vector elements..." << endl;
for (int x : v1)
cout << x << " ";
cout << endl;
//finding the minimum element
int min = *min_element(v1.begin(), v1.end());
cout << "minimum/smallest element is: " << min << endl;
return 0;
}

Output

输出量

vector elements...
10 20 30 40 50
minimum/smallest element is: 10

翻译自: https://www.includehelp.com/stl/find-the-minimum-smallest-element-of-a-vector.aspx

c++ stl 获取最小值

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542363.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android studio panic,Android Studio模拟器PANIC错误

Android Studio模拟器突然停止工作.当我尝试运行虚拟设备时,我在事件日志中收到以下错误.模拟器:PANIC:找不到AVD系统路径.请定义ANDROID_SDK_ROOT仿真器:处理完成,退出代码为1所以我检查了ANDROID_SDK_ROOT环境变量设置的值,它是空的.所以我把它设置为/Users/{username}/Libra…

linux特殊权限之访问权限

特殊权限如/etc/passwd:sSuid:普通用户以管理员身份运行命令&#xff08;chmod us FILE、chmod u-s FILE&#xff09;如果FILE本身原来就有执行权限&#xff0c;SUID显示为s&#xff1b;否则显示SSgid:基本组以管理组身份运行命令&#xff08;chmod gs FILE、chmod g-s FILE&am…

vb.net变量值变化触发事件_Angular变化检测的理解

获取脏检查的时机Angular 使用NgZone获取变化的通知&#xff0c;然后进行全面的变化检测&#xff0c;进而更新Dom脏检查的过程Angular的数据流是自顶而下&#xff0c;从父组件到子组件单项流动&#xff0c;单项数据流保证了高效可预测的变化检测。尽管检查了父组件之后&#xf…

python 算术右移_Python算术序列| 竞争编码问题

python 算术右移Question: 题&#xff1a; In mathematics, when in an arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant then it is called arithmetic constant. 在数学中&#xff0c;当在算术序列中是…

Android8内测申请,小米 6 安卓 8.0 来了 内测开始招募

Android 8.0 已经正式发布多时&#xff0c;目前不少厂商已经启动了旗下进行的 Android 8.0 适配计划。但令人纳闷的是&#xff0c;一向对系统升级比较热心的小米却迟迟没有动静。好消息是&#xff0c;此前网友曝光的消息显示&#xff0c;MIUI 已经悄然在官方论坛中招募小米 6 的…

My linux

为什么80%的码农都做不了架构师&#xff1f;>>> 1.linux 命令方式修改机器名称 # hostname newHostName # vi /etc/sysconfig/network 修改或增加配置&#xff1a;hostnamenewHostName # vi /etc/hosts 修改对应的本地HOST映射 xx.xxx.xxx.xxx newHostName 2.Redha…

狂神说es笔记_人教版七上英语Unit5电子课本音频+课堂笔记+课后同步习题

1人教 七上英语Unit5单词七年级英语上册Unit 5单词默写1做&#xff1b;干(助动词)__________2做&#xff0c;干(助动词第三人称单数形式)__________3有__________4网球__________5球__________6乒乓球______7球棒&#xff1b;球拍__________8(英式)足球____________________9排…

Java RandomAccessFile getFilePointer()方法与示例

RandomAccessFile类getFilePointer()方法 (RandomAccessFile Class getFilePointer() method) getFilePointer() method is available in java.io package. getFilePointer()方法在java.io包中可用。 getFilePointer() method is used to get the current pointer in the Rando…

先进技术android,React Native实战(JavaScript开发iOS和Android应用)/计算机科学先进技术译丛...

导语内容提要本书作者Nader Dabit是AWS Mobile开发人员、React Native Training创始人和React Native Radio播客主持人。本书旨在帮助iOS、Android和Web开发人员学习使用React Native框架&#xff0c;构建高质量的iOS和Android应用程序。书中介绍了React Native入门基础知识&am…

开发类似vs的黑色风格_传闻:2020年《使命召唤》将是《黑色行动》重启作品

据可信度较高的消息源透露&#xff0c;2020 年的《使命召唤》将是《黑色行动》的重启作。而据之前的报道&#xff0c;《黑色行动》开发商 Treyarch 正在开发今年的《使命召唤》&#xff0c; Sledgehammer Games 和 Raven Software 负责辅助工作。该项目代号为“宙斯”&#xff…

ubuntu中 不同JDK版本之间的切换

Ubuntu中JDK 的切换前提是同时安装了多个版本&#xff0c;如jdk7和jdk8&#xff0c;若要切换&#xff0c;在终端输入&#xff1a; sudo update-alternatives --config javasudo update-alternatives --config javac

osi模型:七层模型介绍_联网| OSI模型能力问题和解答 套装1

osi模型:七层模型介绍1) There are the following statements that are given below, which of them are correct about the OSI model? The OSI model is a reference model that describes the network functionalities.The OSI model is an implemented model that describ…

华为鸿蒙系统正式登场,华为自研鸿蒙系统将于8月9日正式登场,还有全新的鸿鹄芯片...

最近华为发布了很多手机&#xff1a;荣耀20系列手机、荣耀9X系列、华为Nova 5系列&#xff0c;以及7月26日发布的华为Nova5i Pro和华为首部5G手机Mate20 X 5G版&#xff0c;这些手机将成为华为下半年的出货主力&#xff0c;市场份额能否超过50%就看这些手机的表现了。华为还将在…

pythonencode和decode_Python3的decode()与encode()

python3的decode()与encode()Tags: Python Python3对于从python2.7过来的人&#xff0c;对python3的感受就是python3对文本以及二进制数据做了比较清晰的区分。文本总是Unicode,由str类型进行表示&#xff0c;二进制数据使用bytes进行表示&#xff0c;不会将str与bytes偷偷的混…

微信小程序 开发 微信开发者工具 快捷键

微信小程序已经跑起来了.快捷键设置找了好久没找到,完全凭感觉.图贴出来.大家看看. 我现在用的是0.10.101100的版本,后续版本更新快捷键也应该不会有什么变化. 现在貌似不能修改.如果有同学找到修改的方法,麻烦告诉我.谢谢. 微信小程序代码编辑快捷键 常用快捷键 格式调整 Ctrl…

java 根据类名示例化类_Java MathContext类| 带示例的getRoundingMode()方法

java 根据类名示例化类MathContext类的getRoundingMode()方法 (MathContext Class getRoundingMode() method) getRoundingMode() method is available in java.math package. getRoundingMode()方法在java.math包中可用。 getRoundingMode() method is used to get the Roundi…

python中xy坐标如何从十个中找到最远的两个_python – Opencv单应性从像素xy坐标中查找全局xy坐标...

我试图找到变换矩阵H,以便我可以乘以(x,y)像素坐标并得到(x,y)真实世界坐标.这是我的代码&#xff1a;import cv2import numpy as npfrom numpy.linalg import invif __name__ __main__ :D[159.1,34.2]I[497.3,37.5]G[639.3,479.7]A[0,478.2]# Read source image.im_src cv2.…

[Android] Android统计Apk , jar包方法数

reference to : http://www.jianshu.com/p/61e8f803e0d1 Android在开发过程中&#xff0c;随着引用的库以及业务的增多&#xff0c;不可避免的会出现64K limit问题&#xff0c;也就是方法数过多的问题&#xff0c;Java代码中的Method总数和Field总数都不能超过65535个&#xff…

type c pin定义_在C中定义宏以设置和清除PIN的位

type c pin定义Given a PIN (value in HEX) and bit number, we have to SET and then CLEAR given bit of the PIN (val) by using Macros. 给定一个PIN(十六进制值)和位数&#xff0c;我们必须使用宏将SET(设置)&#xff0c;然后清除给定的PIN(值)位(值)。 Macros definitio…

android9有深色模式吗,深色模式还是黑色模式?微信把所有人都搞懵了

原标题&#xff1a;深色模式还是黑色模式&#xff1f;微信把所有人都搞懵了前一阵子&#xff0c;微信正式加入了对“深色模式”的支持&#xff0c;这也是除了Windows Phone 版本以外微信第一次从系统层面支持深色模式。虽然这次更新离WWDC上的演示已经过去了9个月&#xff0c;但…