Here you can find the source of minOfArr(int[] arrInput)
Parameter | Description |
---|---|
arrInput | array input |
public static int minOfArr(int[] arrInput)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww . j a v a 2 s .co m*/ * minOfArr will return the minimum value in array. * * @param arrInput array input * @return minimum value */ public static int minOfArr(int[] arrInput) { int min = 0; for (int idx = 1; idx < arrInput.length; idx++) { if (arrInput[idx] != 99999) { min = arrInput[idx] < arrInput[min] ? idx : min; } } return min; } /** * minOfArr will return the minimum value in array with range. * * @param arrInput array input * @param fromIndex starting index * @param toIndex last index * @return minimum value within range */ public static int minOfArr(int[] arrInput, int fromIndex, int toIndex) { int min = fromIndex; int bound = toIndex > arrInput.length ? arrInput.length - 1 : toIndex; for (int idx = fromIndex + 1; idx <= bound; idx++) { if (arrInput[idx] != 99999) { min = arrInput[idx] < arrInput[min] ? idx : min; } } return min; } /** * minOfArr will return the minimum value in array with range and exception. * * @param arrInput array input * @param fromIndex starting index * @param toIndex last index * @param excludeInt integer excluded * @return minimum value within range */ public static int minOfArr(int[] arrInput, int fromIndex, int toIndex, int excludeInt) { if (fromIndex == toIndex) { return fromIndex; } else { int min = fromIndex == excludeInt ? fromIndex + 1 : fromIndex; int bound = toIndex > arrInput.length ? arrInput.length - 1 : toIndex; for (int idx = fromIndex + 1; idx <= bound; idx++) { if (arrInput[idx] != 99999 && idx != excludeInt) { min = arrInput[idx] < arrInput[min] ? idx : min; } } return min; } } }