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 获取最小值
c++ stl 获取最小值_如何在C ++ STL中找到向量的最小/最小元素?相关推荐
- windows命令获取帮助_如何在Windows 10中获得帮助
windows命令获取帮助 Windows 10 has a built-in Get Help app that will offer solutions to problems and even ...
- stl向量_如何在C ++ STL中将数组元素复制到向量?
stl向量 Given an array and we have to copy its elements to a vector in C++ STL. 给定一个数组,我们必须将其元素复制到C ++ ...
- 如何在R代码中找到一个值的行号
如何在R代码中找到一个值的行号? 例如: 在以下一组值中,如何在第4列中找到特定值的行号? 如何使用R代码命令找到列4中的值"1578"的行号. > mydata_2sex ...
- stl标准模板库_如何在C ++ STL(标准模板库)中使用Pair
stl标准模板库 In this article, we'll take a look at using pair in C++ Standard Template Library (STL). 在本 ...
- windows获取本地时间_如何在Windows 8中重新获得本地登录
windows获取本地时间 By default a fresh Windows 8 installation prompts you to create a synchronized cloud-e ...
- 微软输入法的m图标怎么设置_如何在Microsoft Word中获取“ L”形的格式设置图标?...
微软输入法的m图标怎么设置 Each of us has a preferred layout and setup when we are working with Microsoft Word, b ...
- react中纯函数_如何在纯React中创建电子邮件芯片
react中纯函数 by Andreas Remdt 由Andreas Remdt 如何在纯React中创建电子邮件芯片 (How to create email chips in pure Reac ...
- 如何提取edit control中输入的数据_如何在Power Query中提取数据——列表篇(1)
表名为列表,第一步骤名称为源 (一)从头开始提取 1. 获取列表第一个 List.First(list as list, optionaldefaultValue as any)as any 返回列表 ...
- 2008 mysql 本地安全_如何在Linux系统中建立mysql的本地安全机制?
如何在Linux系统中对MySQL进行本地的安全机制?今天我们将给大家介绍下具体的操作方法. local-infile=0#关闭远程连接,即3306端口.这是LinuxMySQL的默认监听端口.由于此 ...
最新文章
- SQL Server 中数据查询注意事项
- Oracle从软件安装到运行的全流程
- 数聚新动能 数创大未来——2016中国国际大数据大会
- 推行法定数字货币,现有支付宝/微信等支付系统,会否被数字货币支付系统替代并超越?
- SQL Server中SQL Union vs Union All
- apache的源代码编译安装
- 14. Thinking carefullly about copying behavior in resource-managing classes
- Unity安装图文步骤
- 2022年最新版黑马程序员Java学习路线
- 极路由2hc5761刷华硕固件_[固件] 【原创首发】极二路由HC5761 9012.1.9227s成功刷成openwrt...
- vim 配置(ma6174 + YCM)
- 电脑微软商店消失解决办法
- java 假设检验_据说假设检验是个很难的题
- 爬了我的微信好友,原来他们是这样的...
- RabbitMQ学习笔记:springboot2 amqp集成生产者消费者
- 塔望 用食品改变世界
- 如何通过脚本开发Android
- 英二变英一,数二变数一!考研人太难了……
- (转)Google Voice呼转到中国电话的五种方法
- 中小学不得在校内设置食品经营场所,量子摩尔定律问世,美团运营摩拜亏45亿,英伟达史上最大手笔收购,这就是今天的大新闻。...
热门文章
- base cap 分布式_干货分享:基于本地消息表的分布式事务解决方案总结
- 关于C++中的unordered_map和unordered_set不能直接以pair作为键名的问题
- 测试网络的带宽指令_单机千万级MQTT服务器测试报告
- linux 脚本批量删除,Linux Shell使用Bash脚本批量删除文件
- Linux Server 安装 raid 1
- Typescript实现单例之父类调用子类
- webpack4打包工具
- ubuntu进行apt-get时候出现Package ssh is not available, but is referred to by another package 错误...
- eclipse快捷键、智能提示
- sharepoint 2007功能增强解决方案,资料收集