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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

stl min函数_std :: min_element()函数以及C ++ STL中的示例

發(fā)布時間:2025/3/11 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl min函数_std :: min_element()函数以及C ++ STL中的示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

stl min函數(shù)

C ++ STL std :: min_element()函數(shù) (C++ STL std::min_element() function)

min_element() function is a library function of algorithm header, it is used to find the smallest element from the range, it accepts a container range [start, end] and returns an iterator pointing to the element with the smallest value in the given range.

min_element()函數(shù)是算法標(biāo)頭的庫函數(shù),用于查找范圍中的最小元素,它接受容器范圍[start,end],并返回指向指定范圍內(nèi)具有最小值的元素的迭代器。

Additionally, it can accept a function as the third argument that will perform a conditional check on all elements.

此外,它可以接受函數(shù)作為第三個參數(shù),它將對所有元素執(zhí)行條件檢查。

Note: To use min_element() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.

注意:要使用min_element()函數(shù) –包括<algorithm>頭文件,或者您可以簡單地使用<bits / stdc ++。h>頭文件。

Syntax of std::min_element() function

std :: min_element()函數(shù)的語法

std::min_element(iterator start, iterator end, [compare comp]);

Parameter(s):

參數(shù):

  • iterator start, iterator end – these are the iterator positions pointing to the ranges in the container.

    迭代器開始,迭代器結(jié)束 –這些是指向容器中范圍的迭代器位置。

  • [compare comp] – it's an optional parameter (a function) to be compared with elements in the given range.

    [compare comp] –它是一個可選參數(shù)(一個函數(shù)),可以與給定范圍內(nèi)的元素進行比較。

Return value: iterator – it returns an iterator pointing to the element with the smallest value in the given range.

返回值: iterator –它返回一個迭代器,該迭代器指向給定范圍內(nèi)具有最小值的元素。

Example:

例:

Input:int arr[] = { 100, 200, -100, 300, 400 };//finding smallest elementint result = *min_element(arr + 0, arr + 5);cout << result << endl;Output:-100

C ++ STL程序演示std :: min_element()函數(shù)的使用 (C++ STL program to demonstrate use of std::min_element() function)

In this program, we have an array and a vector and finding their smallest elements.

在此程序中,我們有一個數(shù)組和一個向量并找到它們的最小元素。

//C++ STL program to demonstrate use of //std::min_element() function #include <iostream> #include <algorithm> #include <vector> using namespace std;int main() {//an arrayint arr[] = { 100, 200, -100, 300, 400 };//a vectorvector<int> v1{ 10, 20, 30, 40, 50 };//finding smallest element from the arrayint result = *min_element(arr + 0, arr + 5);cout << "smallest element of the array: " << result << endl;//finding smallest element from the vectorresult = *min_element(v1.begin(), v1.end());cout << "smallest element of the vector: " << result << endl;return 0; }

Output

輸出量

smallest element of the array: -100 smallest element of the vector: 10

Reference: C++ std::min_element()

參考: C ++ std :: min_element()

翻譯自: https://www.includehelp.com/stl/std-min_element-function-with-example.aspx

stl min函數(shù)

總結(jié)

以上是生活随笔為你收集整理的stl min函数_std :: min_element()函数以及C ++ STL中的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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