Compute the median of the data set as the midpoint between the two middle

values when the data set has an even number of elements.

PR:		201582
Submitted by:	Marcus Reid <marcus@blazingdot.com>
Reviewed by:	imp
Approved by:	bapt (mentor)
This commit is contained in:
araujo 2015-11-24 02:30:59 +00:00
parent ba54012c27
commit 835b818769

View File

@ -192,8 +192,10 @@ Avg(struct dataset *ds)
static double
Median(struct dataset *ds)
{
return (ds->points[ds->n / 2]);
if ((ds->n % 2) == 0)
return ((ds->points[ds->n / 2] + (ds->points[(ds->n / 2) - 1])) / 2);
else
return (ds->points[ds->n / 2]);
}
static double