Java Array Min Value min(T[] inputArray, int i, int i0)

Here you can find the source of min(T[] inputArray, int i, int i0)

Description

Finds the minimum element between to specified indexes of an array

License

Open Source License

Parameter

Parameter Description
T Type that implements Comparable
inputArray An array of elements of type Comparable
i The starting index
i0 The ending index

Return

The smallest index between the two specified input indices.

Declaration

private static <T extends Comparable> int min(T[] inputArray, int i, int i0) 

Method Source Code

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

public class Main {
    /**//from www .jav  a  2  s. c  o  m
     * Finds the minimum element between to specified indexes of an array
     *
     * @param <T>        Type that implements Comparable
     * @param inputArray An array of elements of type Comparable
     * @param i          The starting index
     * @param i0         The ending index
     * @return The smallest index between the two specified input indices.
     */
    private static <T extends Comparable> int min(T[] inputArray, int i, int i0) {
        int smallestIndex = i; //set default smallest index to i
        i++; //increment i so that we don't compare index to itself
        while (i <= i0) { //loop through range specified by index params
            //if object in index is smaller than specified object...
            if (inputArray[i].compareTo(inputArray[smallestIndex]) < 0) {
                smallestIndex = i; //set lowIndex to that of new smaller object
            }
            i++;
        }
        return smallestIndex;
    }
}

Related

  1. min(Number... array)
  2. min(Number[] array)
  3. min(T first, T... others)
  4. min(T... values)
  5. min(T[] args)
  6. min_max_mean_stddev(long[] counts)
  7. min_of_ints(int[] data)
  8. minAndMaxOfArray(float[] array)
  9. minarr(double[] a)