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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

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

發(fā)布時間:2025/3/11 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++ stl 获取最小值_如何在C ++ STL中找到向量的最小/最小元素? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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>標(biāo)頭中定義的* min_element()函數(shù) 。 它接受一定范圍的迭代器,我們必須從中查找最小/最小元素,然后返回指向給定范圍之間的最小元素的迭代器。

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()函數(shù) –包含<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.

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

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() {//vectorvector<int> v1{ 10, 20, 30, 40, 50 };//printing elementscout << "vector elements..." << endl;for (int x : v1)cout << x << " ";cout << endl;//finding the minimum elementint 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 獲取最小值

總結(jié)

以上是生活随笔為你收集整理的c++ stl 获取最小值_如何在C ++ STL中找到向量的最小/最小元素?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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