Skip to content

Instantly share code, notes, and snippets.

@halit
Created May 31, 2014 17:15
Show Gist options
  • Save halit/b424f1a0134a68c982ea to your computer and use it in GitHub Desktop.
Save halit/b424f1a0134a68c982ea to your computer and use it in GitHub Desktop.
Simple implementation of quick sort
void quicksort(int* a, int n){
int i, last;
if(n <= 1) return;
swap(a, 0, rand()%n);
last = 0;
for(i=1;i<n;i++) if(a[i] < a[0]) swap(a, ++last, i);
swap(a, 0, last);
quicksort(a, last);
quicksort(a+last+1, n-last-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment