Here you can find the source of medianFromHistogram(int[] hist)
private static int medianFromHistogram(int[] hist)
//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; } }