mardi 31 décembre 2019

Why is min_element() returning the index of the minimum element in the following

min_element is supposed to return a pointer pointing to the minimum element in a array or vector but here why is it returning a position of the element with minimum value.

int n; cin>>n;
vector<int> arr(n);
for(int i=0;i<n;i++)
    cin>>arr[i];

int minElementIndex = min_element(arr.begin(),arr.end()) - arr.begin();
cout<<minElementIndex;

Aucun commentaire:

Enregistrer un commentaire