Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QuickSort
//gcc 4.9.3 #include <stdio.h> int partition( int a[], int l, int r) { int pivot, i, j, t; pivot = a[l]; i = l; j = r+1; while( 1) { do ++i; while( a[i] <= pivot && i <= r ); do --j; while( a[j] > pivot ); if( i >= j ) break; t = a[i]; a[i] = a[j]; a[j] = t; } t = a[l]; a[l] = a[j]; a[j] = t; return j; } void quickSort( int *a, int l, int r) { int j; if( l < r ) { // divide and conquer j = partition( a, l, r); quickSort( a, l, j-1); quickSort( a, j+1, r); } } int main(void) { int arr[10] = {10,9,8,7,6,5,4,3,2,1}; quickSort(arr,0,9); for(int i = 0; i < 10; i++){ printf("%d ",arr[i]); } return 0; }
run
|
edit
|
history
|
help
0
figa gratis
Silly circular pointer
Translating binary to decimal numbers
cppPyClass
Boost phoenix. e.g 2: functor
single_digit
Procesos E
binary
My First Wall
Extended Euclidean Algorithm