Is there a standard function that returns the position (not value) of the maximum element of an array of values?
For example:
Suppose I have an array like this:
sampleArray = [1, 5, 2, 9, 4, 6, 3]
I want a function that returns the integer of 3 that tells me that sampleArray[3]
is the largest value in the array.
Best Answer
In the STL,
std::max_element
provides the iterator (which can be used to get index withstd::distance
, if you really want it).