13 #ifndef INCLUDED_UTILITY_MINMAX_HH
14 #define INCLUDED_UTILITY_MINMAX_HH
29 int argmin(
const std::vector<T>& iterable) {
30 if ( iterable.size() == 0 ) {
35 for ( std::size_t curr_idx = 1; curr_idx < iterable.size(); ++curr_idx ) {
36 if ( iterable[curr_idx] < iterable[min_idx] ) {
48 if ( iterable.size() == 0 ) {
53 for ( std::size_t curr_idx = 2; curr_idx <= iterable.size(); ++curr_idx ) {
54 if ( iterable[curr_idx] < iterable[min_idx] ) {
67 int argmax(
const std::vector<T>& iterable) {
68 if ( iterable.size() == 0 ) {
73 for ( std::size_t curr_idx = 1; curr_idx < iterable.size(); ++curr_idx ) {
74 if ( iterable[curr_idx] > iterable[max_idx] ) {
86 if ( iterable.size() == 0 ) {
91 for ( std::size_t curr_idx = 2; curr_idx <= iterable.size(); ++curr_idx ) {
92 if ( iterable[curr_idx] > iterable[max_idx] ) {
102 #endif // INCLUDED_UTILITY_MINMAX_HH
int argmax(const std::vector< T > &iterable)
Returns the argument whose value is maximal according to operator>.
int argmin(const std::vector< T > &iterable)
Returns the argument whose value is minimal according to operator<.
vector1: std::vector with 1-based indexing