-
Notifications
You must be signed in to change notification settings - Fork 0
/
vp_utilities.c
53 lines (40 loc) · 1.13 KB
/
vp_utilities.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <math.h>
#include <stdio.h>
void radixsort(int *array, int n) {
int i, b[n], exp = 1;
int m = array[0];
for (i = 1; i < n; i++) // find number with max digits
if (array[i] > m)
m = array[i];
while ((m / exp) > 0) {
int bucket[10] = {0};
for (i = 0; i < n; i++)
bucket[(array[i] / exp) % 10]++;
for (i = 1; i < 10; i++)
bucket[i] += bucket[i - 1];
for (i = n - 1; i >= 0; i--)
b[--bucket[(array[i] / exp) % 10]] = array[i]; // sort with digit
for (i = 0; i < n; i++)
array[i] = b[i];
exp *= 10;
}
}
float standard_deviation(int *data, int n) {
float mean = 0.0, sum_deviation = 0.0;
int i;
for (i = 0; i < n; ++i)
mean += data[i];
mean = mean / n;
for (i = 0; i < n; ++i)
sum_deviation += (data[i] - mean) * (data[i] - mean);
return sqrt(sum_deviation / n);
}
int FindMax(float *standard_dev, int n) {
int maxi = standard_dev[0];
int i, x = 0;
for (i = 1; i != n; i++) {
if (standard_dev[i] > maxi)
x = i;
}
return x;
}