minimum values in an array

Mar 13, 2014 at 9:04pm
i need to find the minimum values in an array and print the indexs corresponding to the elements out.
There are identical minimum values in a array,the size of the array is unknown. how can i find and print the indexs corresponding to the elements out?
Mar 13, 2014 at 10:13pm
well you could sort the array then the minimum value will always be the first element.

//sort algorithm
http://www.cplusplus.com/reference/algorithm/sort/

//there is also the min_element function which returns an iterator to the min element.
http://www.cplusplus.com/reference/algorithm/min_element/
Mar 13, 2014 at 11:02pm
Sorting changes indices, so it seems inappropriate.

std::min_element returns the location of first minimal element. It is trivial to find the rest.

std::distance helps changing iterator into index.
Topic archived. No new replies allowed.