Here you can find the source of median(int x[], int pos1, int pos2, int pos3)
private static int median(int x[], int pos1, int pos2, int pos3)
//package com.java2s; /**//w ww . jav a 2s . c om * **************************************************************************** * Copyright (c) 2008 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * SAP AG - initial API and implementation * ***************************************************************************** */ public class Main { private static int median(int x[], int pos1, int pos2, int pos3) { int v1 = x[pos1]; int v2 = x[pos2]; int v3 = x[pos3]; if (v1 < v2) { if (v2 <= v3) { return pos2; } else { return v1 < v3 ? pos3 : pos1; } } /* else -> v1 > v2 */ if (v1 <= v3) { return pos1; } else { return v2 < v3 ? pos3 : pos2; } } private static int median(long x[], int pos1, int pos2, int pos3) { long v1 = x[pos1]; long v2 = x[pos2]; long v3 = x[pos3]; if (v1 < v2) { if (v2 <= v3) { return pos2; } else { return v1 < v3 ? pos3 : pos1; } } /* else -> v1 > v2 */ if (v1 <= v3) { return pos1; } else { return v2 < v3 ? pos3 : pos2; } } }