I have an array of values ββand a method to find the index of the largest element in the array.
value = distance(arrayOfValues, max_element(arrayOfValues, arrayOfValues + N));
However, if there are several instances of the highest value, for example. {3,1,3,4,4,3,2} it only returns the smallest index (in this case 3), while I would like it to return the largest index, in this case 4.
The only way I can do this is to create a new array identical to "arrayOfValues", but vice versa, and then apply the above method.
Is there an easier way to do this to avoid creating a new array? Perhaps manipulating the above code snippet?
source
share