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
---DISEÑO DE TECLADO---
C_141126_ArrayMayorMenor01
Assignment 8
Str_ptr_arg
WAP in C to print the reverse of a string
Lab 11 v.05
FloatInt
funciones matrices
K&R/1_3
Lab 7 blackjack v0.5