/* primer59.c - pokazivac na funkciju */ #include #define MAX 10 void sort( int (*comp)( int, int ) ); void trampa( int *, int *); int rastuci( int, int ); int opadajuci( int, int ); int T[10] = { 4, 77, 1, 9, 56, 33, 11, 3, 6, 1}; void main() { int i; sort( opadajuci ); for(i = 0; i < 10; i++ ) printf("%d ", T[i] ); putchar('\n'); sort( rastuci ); for(i = 0; i < 10; i++ ) printf("%d ", T[i] ); } void sort( int comp(int, int) ) { int i, j, min; for( i = 0; i < MAX; i++ ) { min = i; for( j = i+1; j < MAX; j++ ) if( comp( T[j], T[min] )) min = j; trampa( &T[min], &T[i] ); } } int rastuci( int x, int y ) { return (x < y); } int opadajuci( int x, int y ) { return (x > y); } void trampa( int *x, int *y ) { int temp ; temp = *x; *x = *y; *y = temp; }