stl向量最大值_C ++ STL中向量的最小和最大元素
stl向量最大值
Given a vector and we have to find the smallest (minimum) and largest (maximum) elements.
給定一個向量,我們必須找到最小(最小)和最大(最大)元素。
查找向量的最小和最大元素 (Finding vector's minimum & maximum elements)
To find minimum element of a vector, we use *min_element() function and to find the maximum element, we use *max_element() function.
要找到向量的最小元素,請使用* min_element()函數 ,要找到最大元素,請使用* max_element()函數 。
Syntax:
句法:
*max_element(iterator start, iterator end);*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 and maximum value.
在這里, 迭代器開始,迭代器結束是它們之間向量中迭代器的位置,我們必須找到最小值和最大值。
These functions are defined in <algorithm> header or we can use <bits/stdc++.h> header file.
這些函數在<algorithm>頭文件中定義,或者我們可以使用<bits / stdc ++。h>頭文件。
Example:
例:
Input:vector<int> v1{ 10, 20, 30, 40, 50, 25, 15 };cout << *min_element(v1.begin(), v1.end()) << endl;cout << *max_element(v1.begin(), v1.end()) << endl;Output:1050C ++ STL程序查找向量的最小和最大元素 (C++ STL program to find minimum and maximum elements of a vector )
//C++ STL program to append a vector to a vector #include <bits/stdc++.h> using namespace std;int main() {//vector declarationvector<int> v1{ 10, 20, 30, 40, 50, 25, 15 };int min = 0;int max = 0;//finding minimum & maximum elementmin = *min_element(v1.begin(), v1.end());max = *max_element(v1.begin(), v1.end());cout << "minimum element of the vector: " << min << endl;cout << "maximum element of the vector: " << max << endl;return 0; }Output
輸出量
minimum element of the vector: 10 maximum element of the vector: 50翻譯自: https://www.includehelp.com/stl/minimum-and-maximum-elements-of-a-vector.aspx
stl向量最大值
總結
以上是生活随笔為你收集整理的stl向量最大值_C ++ STL中向量的最小和最大元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中map的遍历方法_Java中M
- 下一篇: 计算机基础应用的培养活动记录,小学少年宫