Главная
>>
Каталог задач
>>
Статистика
>>
Элементарное
>>
Вычисление медианы заданной выборки
Вычисление медианы заданной выборки
реализации: C, количество: 2
Aвтор: this
Дата: 27.04.2006
Просмотров: 13803
Рейтинг:
7/3,4.82(1281)
+
реализации(исходники)
+добавить
Примеры вычисления медианы заданной выборки
Реализации:
C(2)
+добавить реализацию
1)
Вычисление медианы заданной выборки #1, code #108[автор:-]
/* bs03r.f -- translated by f2c (version 20000817).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
#include "f2c.h"
/* Subroutine */ int bs03r_c(real *x, integer *n, real *xmed)
{
extern /* Subroutine */ int bs03r1_c(integer *, real *);
static integer n2;
/* Parameter adjustments */
--x;
/* Function Body */
bs03r1_c(n, &x[1]);
n2 = *n / 2;
*xmed = x[n2 + 1];
if (n2 << 1 == *n) {
*xmed = (x[n2] + x[n2 + 1]) * .5f;
}
return 0;
} /* bs03r_c */
2)
Вычисление медианы заданной выборки #2, code #109[автор:-]
/* bs03r1.f -- translated by f2c (version 20000817).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
#include "f2c.h"
/* Subroutine */ int bs03r1_c(integer *n, real *ra)
{
static integer i__, j, l, ir;
static real rra;
/* Parameter adjustments */
--ra;
/* Function Body */
l = *n / 2 + 1;
ir = *n;
L10:
if (l <= 1) {
goto L51;
}
--l;
rra = ra[l];
goto L52;
L51:
rra = ra[ir];
ra[ir] = ra[1];
--ir;
if (ir != 1) {
goto L52;
}
ra[1] = rra;
return 0;
L52:
i__ = l;
j = l + l;
L20:
if (j > ir) {
goto L55;
}
if (j < ir && ra[j] < ra[j + 1]) {
++j;
}
if (rra >= ra[j]) {
goto L53;
}
ra[i__] = ra[j];
i__ = j;
j += j;
goto L54;
L53:
j = ir + 1;
L54:
goto L20;
L55:
ra[i__] = rra;
goto L10;
} /* bs03r1_c */