Median

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



									Public Shared Function Median(data As Double()) As Double
	Array.Sort(data)

	If data.Length Mod 2 = 0 Then
		Return (data(data.Length \ 2 - 1) + data(data.Length \ 2)) / 2
	Else
		Return data(data.Length \ 2)
	End If
End Function
								


Example

									Dim data As Double() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim medianVal As Double = Median(data)
								


Output

									5.5