-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.c
81 lines (80 loc) · 1.12 KB
/
group.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
int main()
{
int i, N, m, n, p;
double *x, *y, *t;
printf("Input N:");
scanf("%d", &N);
x = (double *) malloc(N*sizeof(double));
y = (double *) malloc(N*sizeof(double));
for(i=0;i<N;++i)
{
x[i] = i;
}
for(i=0;i<N;++i)
printf("%f\n", x[i]);
n = N;
while(n>1)
{
m = 0;
while(m < N)
{
if(n%2 == 0)
{
p = 2;
}
else if (n%3 == 0)
{
p = 3;
}
Group_p(x+m,y+m,n,p);
m = m + n;
}
t = x; x = y; y = t;
n = n / p;
}
for(i=0;i<N;++i)
printf("%f\n", x[i]);
}
int Group_2(double *x, double *y, int N)
{
int i;
// Group by (2n) (2n+1)
for(i=0;i<N/2;++i)
{
//y[i] = x[2*i];
//y[i+N/2] = x[2*i+1];
}
// other way!
for(i=0;i<N;++i)
{
y[(i/2) + (N/2)*(i%2)] = x[i];
}
return 0;
}
int Group_3(double *x, double *y, int N)
{
int i;
// Group by (2n) (2n+1)
for(i=0;i<N/2;++i)
{
y[i] = x[3*i];
y[i+N/3] = x[3*i+1];
y[i+2*N/3] = x[3*i+2];
}
// other way!
for(i=0;i<N;++i)
{
y[(i/3) + (N/3)*(i%3)] = x[i];
}
return 0;
}
int Group_p(double *x, double *y, int N, int p)
{
int i;
for(i=0;i<N;++i)
{
y[(i/p) + (N/p)*(i%p)] = x[i];
}
return 0;
}