vector<int> card; 最大值:int maxValue = *max_element(card.begin(),card.end()); 最小值:int minValue = *min_element(card.begin(),card.end()); 最大值下标索引:int maxPosition = max_element(card.begin(),card.end()) - card.begin(); 最小值下标索引:int minPosition = min_element(...
#include<iostream>#include<vector>#include<algorithm>using namespace std;intmain(int argc,char**argv){float arr[]={1.0,2.0,3.5,6.7,1.22,0.77,90.0,36.11};int arr_length=sizeof(arr)/sizeof(arr[0]);// 数组长度// max_element(arr, arr+arr_length) 计算出来是一个地址,我们需要取该地址的...
//说明:max_element(v.begin(), v.end()) 返回的是vector<double>::iterator, //相当于指针的位置,减去初始指针的位置结果即为最大值得索引。 auto smallest = std::min_element(std::begin(v), std::end(v)); std::cout << "min element is " << *smallest<< " at position " <<std::dis...
intarr_length =sizeof(arr) /sizeof(arr[0]);// 数组长度 // max_element(arr, arr+arr_length) 计算出来是一个地址,我们需要取该地址的值 cout<<"max val is: "<< *max_element(arr, arr+arr_length) <<"t the max val index is "<< max_element(arr, arr + arr_length)-arr <<endl;...