Java Median medianIndexInSorted(double[] arr)

Here you can find the source of medianIndexInSorted(double[] arr)

Description

median Index In Sorted

License

Open Source License

Declaration

public static int medianIndexInSorted(double[] arr) 

Method Source Code


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

import java.util.*;

public class Main {
    public static int medianIndexInSorted(double[] arr) {
        // TODO: Better tie breaking?
        Arrays.sort(arr);//from   w w w. j  a  v  a2s.c o m
        if (arr.length < 2) {
            return 0;
        } else if (arr.length % 2 == 0) {
            // return the higher of the 2 midpoints
            return (arr.length / 2);
        } else {
            // return exactly the midpoint
            return ((arr.length - 1) / 2);
        }
    }
}

Related

  1. median_sorted(double[] sorted)
  2. medianAndSort(double[] a)
  3. medianElement(float[] array, int size)
  4. medianFilter(double[] array, int window)
  5. medianFromHistogram(int[] hist)
  6. medianOfMedians(int[] array)