min_element(): This is a build-in function in STL. This function is available in the file stl_algo.h. This function returns an iterator pointing to the element with the smallest value in the range [first, last).
Syntax:
std::min_element(__first,__last)
Parameters: Two parameters are required for this function.
__first – Start of range.
__last – End of range.
For Example:
arr = {5,34,3,12,4,21}
vector<int>::iterator it = min_element(arr.beigin(),arr.end()) = > It returns an iterator pointing to 3.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> arr = {5, 34, 3, 12, 4, 21};vector<int>::iterator it = min_element(arr.begin(),arr.end());cout << *it << "\n";return 0;}
No comments:
Post a Comment