【发布时间】:2012-07-21 22:49:27
【问题描述】:
可能重复:
Finding the median value of an array?
How to calculate mean, median, mode and range from a set of numbers
Combine QuickSort and Median selection algorithm
如何找到随机生成的数组的中值?
例如:它会给我一个像 88,23,93,65,22,43 这样的数组。 我使用的代码找到了中间的数字,但它没有排序。
这是我目前使用的代码:
double Median()
{
int Middle = TheArrayAssingment.length / 2;
if (TheArrayAssingment.length%2 == 1)
{
return TheArrayAssingment[Middle];
}
else {
return (TheArrayAssingment[Middle-1] + TheArrayAssingment[Middle]) / 2.0;
}
}
【问题讨论】:
-
不要忘记发布您的代码。
-
为什么不先对数组进行排序呢?
-
有人问过这个问题before