Java Median medianFromHistogram(int[] hist)

Here you can find the source of medianFromHistogram(int[] hist)

Description

median From Histogram

License

Open Source License

Declaration

private static int medianFromHistogram(int[] hist) 

Method Source Code

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

public class Main {
    private static int medianFromHistogram(int[] hist) {
        int pos_l = 0, pos_r = hist.length - 1;
        int sum_l = hist[pos_l], sum_r = hist[pos_r];

        while (pos_l < pos_r) {
            if (sum_l < sum_r) {
                sum_l += hist[++pos_l];//from   w  w  w .j av  a  2s.co m
            } else {
                sum_r += hist[--pos_r];
            }
        }
        return pos_l;
    }
}

Related

  1. median_of_3(int[] x, int x_ptr)
  2. median_sorted(double[] sorted)
  3. medianAndSort(double[] a)
  4. medianElement(float[] array, int size)
  5. medianFilter(double[] array, int window)
  6. medianIndexInSorted(double[] arr)
  7. medianOfMedians(int[] array)