Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * trollsort - sorts an array of n integers - (the troll way) Kappa Keepo
- * ----------------------------------------------------------------------
- * just some code i wrote for fun. i think complexity should be same with
- * bubblesort O(n^2) altho im not sure. feel free to explore it yourself.
- * obviously its easy to break it but runs ok for most cases.
- * kappasort O(nlogn) coming soon...
- * ----------------------------------------------------------------------
- * WARNING!!! the is a million undefined behavior things in this code plz
- * follow instructions to compile it correctly-ish
- * ----------------------------------------------------------------------
- * Leonidas Giannoulis - masterleo@gmail.com - http://cdev.ml/ - May 2015
- */
- int trollsort(int A[], int n)<%
- return n?n<~n?n=-n,trollsort(A,-~-n),A[~-n:>>n<:A]&&(n[A]^=A[~-n]^=n[A]^=A[~-n]):trollsort(A,-~-n)|trollsort(A,~-n):420;
- %>
- /*
- * You can use this code to test it.
- * Runs smooth on http://www.tutorialspoint.com/unix_terminal_online.php
- * compile: cc -O2 -std=c99 trollsort.c -o trollsort
- * example run: ./trollsort -1 1 69 0 -666 420 1337
- */
- #include <stdio.h>
- int print_array_ascending(int *A, int n)<%
- return n&&printf("%d ",*A)|print_array_ascending(++A,--n)||putchar(0xA);
- }
- int main(int argc, char *argv[])<%
- int n=--argc,A[n];
- /* Load */
- while(argc--&&sscanf(argv<:-~argc],"%d",A+argc));
- /* Sort */
- trollsort(A,n);
- /* Print */
- fputs("Sorted Result: ",stdout)|print_array_ascending(A,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement