Java Array Min Value minIndex(double values[])

Here you can find the source of minIndex(double values[])

Description

Finds the index of the minimum value in the given vector.

License

Open Source License

Parameter

Parameter Description
values the vector

Return

index of the minimum in the given vector

Declaration

public static int minIndex(double values[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//ww w. j a  v a  2 s  .  c  o m
     * Finds the index of the minimum value in the given vector.
     * @param values the vector
     * @return index of the minimum in the given vector
     */
    public static int minIndex(double values[]) {
        double min = Double.NEGATIVE_INFINITY;
        int minIndex = 0;
        int index = 0;
        for (double value : values) {
            if (value < min) {
                min = value;
                minIndex = index;
            }
            index++;
        }
        return minIndex;
    }

    /**
     * Finds the index of the minimum value in the given vector.
     * @param values the vector
     * @param mask mask denoting from which elements the minimum should be selected
     * @return index of the minimum in the given vector (w.r.t. the given mask)
     */
    public static int minIndex(double values[], boolean[] mask) {
        double min = Double.NEGATIVE_INFINITY;
        int minIndex = 0;
        int index = 0;
        for (double value : values) {
            if (mask[index] && value < min) {
                min = value;
                minIndex = index;
            }
            index++;
        }
        return minIndex;
    }

    /**
     * Finds the index of the minimum value in the given vector.
     * @param values the vector
     * @param mask mask denoting from which elements the minimum should be selected
     * @return index of the minimum in the given vector (w.r.t. the given mask)
     */
    public static int minIndex(int values[]) {
        int min = Integer.MAX_VALUE;
        int minIndex = 0;
        int index = 0;
        for (int value : values) {
            if (value < min) {
                min = value;
                minIndex = index;
            }
            index++;
        }
        return minIndex;
    }
}

Related

  1. minimum(int... values)
  2. minimumDotProduct(int[] a, int[] b)
  3. minimumOf(final int[] array)
  4. minimumWordLength(String[] words)
  5. minIn(double[] array)
  6. minIndex(double... data)
  7. minIndex(double[] a)
  8. minIndex(double[] arr)
  9. minIndex(double[] list)