Java Array Min Value argMin(int[] a)

Here you can find the source of argMin(int[] a)

Description

arg Min

License

Open Source License

Parameter

Parameter Description
a a parameter

Return

the index of a minimum value in a

Declaration

public static int argMin(int[] a) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * OscaR is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.//w  ww. j a v  a2s .c om
 *   
 * OscaR is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License  for more details.
 *   
 * You should have received a copy of the GNU Lesser General Public License along with OscaR.
 * If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
 ******************************************************************************/

public class Main {
    /**
     *
     * @param a
     * @return  the index of a minimum value in a
     */
    public static int argMin(int[] a) {
        int v = Integer.MAX_VALUE;
        int ind = -1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] < v) {
                v = a[i];
                ind = i;
            }
        }
        return ind;
    }
}

Related

  1. argmin(double... vs)
  2. argmin(final double[] vec)
  3. argmin(int[] a)
  4. arrayMin(double minVal, double[] vals)
  5. arrayMin(double[] arr)
  6. arrayMin(double[] x)
  7. arrayMin(final double[] array)