Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * code by fb.me/masterleo
- * di.uoa.gr 10/08/2015
- * gcc -O3 -o qs qs.c
- *
- * QuickSort Brainfuck
- * >>+>>>>>,[>+>>,]>+[--[+<<<-]<[<+>-]<[<[->[<<<+>>>>+<-]<<[>>+>[->]<<[<]
- * <-]>]>>>+<[[-]<[>+<-]<]>[[>>>]+<<<-<[<<[<<<]>>+>[>>>]<-]<<[<<<]>[>>[>>
- * >]<+<<[<<<]>-]]+<<<]+[->>>]>>]>>[.>>>]
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #define N 100
- qs(int *a,int o,int n) <%
- return n<~n?n<:a:><*a&&a[n:>!=a<:++o]&&(a[n]^=a[o]^=a[n]^=a[o]),qs(a,o,-~n):n^n<~-n?o=n+qs(a+~-n,-n,-~-n),o<:a]!=a[~-n:>&&(a[o]^=a[~-n]^=a[o]^=a[~-n]),qs(a,o-o,o),qs(a+-~o,n%n,~-n-o):o;
- %>
- main() {
- int n=N, *a = malloc (N * sizeof (int));
- srand(time(NULL));
- while (n--) printf("%d ", a[n] = rand() % N);
- puts("");
- clock_t t1 = clock();
- qs(a, 0, n=N);
- clock_t t2 = clock();
- puts("");
- while (n--) printf("%d ",*a++);
- printf("\n%f seconds\n", ((double)(t2 - t1)) / CLOCKS_PER_SEC );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement