diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-15 03:24:33 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-15 03:24:33 +0200 |
commit | cf3a29feb5887344b6633ead1b4b6d5657a15a4b (patch) | |
tree | f1149508f7305a48dba0226699dfafdd68d81969 /algorithms/blasort.c | |
parent | 5ddc763ab9953eebdaf78af4eb72288d7955b310 (diff) |
old stuff: algorithms
Diffstat (limited to 'algorithms/blasort.c')
-rw-r--r-- | algorithms/blasort.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/algorithms/blasort.c b/algorithms/blasort.c new file mode 100644 index 0000000..40c4c3e --- /dev/null +++ b/algorithms/blasort.c @@ -0,0 +1,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; +} + |