日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

stl向量最大值_C ++ STL中向量的最小和最大元素

發(fā)布時(shí)間:2025/3/11 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl向量最大值_C ++ STL中向量的最小和最大元素 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

stl向量最大值

Given a vector and we have to find the smallest (minimum) and largest (maximum) elements.

給定一個(gè)向量,我們必須找到最小(最小)和最大(最大)元素。

查找向量的最小和最大元素 (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.

要找到向量的最小元素,請(qǐng)使用* min_element()函數(shù) ,要找到最大元素,請(qǐng)使用* max_element()函數(shù) 。

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.

在這里, 迭代器開(kāi)始,迭代器結(jié)束是它們之間向量中迭代器的位置,我們必須找到最小值和最大值。

These functions are defined in <algorithm> header or we can use <bits/stdc++.h> header file.

這些函數(shù)在<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:1050

C ++ 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向量最大值

總結(jié)

以上是生活随笔為你收集整理的stl向量最大值_C ++ STL中向量的最小和最大元素的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。