/* primer54.c - quicksort */ #include void qs( int, int ); int particija( int, int ); void trampa( int *, int *); int T[10] = { 4, 77, 1, 9, 56, 33, 11, 3, 6, 1}; int inf = 0, sup = 9; void main() { int i; qs( inf, sup ); for(i = 0; i < 10; i++ ) printf("%d ", T[i] ); } void qs( int inf, int sup ) { if( inf < sup ) { int i; i = particija( inf, sup); printf("%d %d %d\n", inf, sup, i ); qs( inf, i - 1 ); qs( i + 1, sup ); } } int particija( int inf, int sup ) { int l, k, m; l = inf + 1; m = sup; k = T[inf]; //Stozer while( l <= m) { if( T[l] <= k ) l = l + 1; else { while( T[m] > k ) m = m - 1; if( l < m ) { trampa( &T[l], &T[m] ); m = m - 1; l = l + 1; } } } trampa( &T[m], &T[inf] ); return m; } void trampa( int *x, int *y ) { int temp ; temp = *x; *x = *y; *y = temp; }