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
|
#include <stdio.h>
#define N 4
int* c=0;
void
blasort(int* A, int i, int j)
{
int tmp;
if(A[i]>A[j]) {
tmp=A[i];
A[i] = A[j];
A[j] = tmp;
}
if(i+1>j || i+1==j) {
return;
}
int k=(j-i+1)/3;
blasort(A,i,j-k);
blasort(A,i+k,j);
blasort(A,i,j-k);
*c++;
}
int main(int argc, char** argv)
{
int A[N] = {4,3,2,1};
blasort(A,0,N-1);
unsigned int i;
for(i=0; i<N; i+=1) {
printf("%d ",A[i]);
}
printf("|C=%d\n",c);
return 0;
}
|