Median

This algorithm computes the median of the given set of numbers.



									public static double Median(double[] data)
{
	Array.Sort(data);

	if (data.Length % 2 == 0)
		return (data[data.Length / 2 - 1] + data[data.Length / 2]) / 2;
	else
		return data[data.Length / 2];
}
								


Example

									double[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double median = Median(data);
								


Output

									5.5