1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <stdio.h>
#include <stdlib.h>
void printinttab(int* tab, int taille){
int i;
for(i = 0; i < taille; i++){
printf("%d - %d\n", i, tab[i]);
}
}
int compareint(const void* a, const void* b){
return *(int*)a - *(int*)b;
}
int main(void) {
#define PETRUS_TAILLE (sizeof rats / sizeof(int))
int rats[] = {1, 2, 3, 5, 6, 0};
rats[PETRUS_TAILLE - 1] = 4;
puts("rats pas triés:");
printinttab(rats, PETRUS_TAILLE);
qsort(rats, PETRUS_TAILLE, sizeof(int), compareint);
puts("rats triés:");
printinttab(rats, PETRUS_TAILLE);
#undef PETRUS_TAILLE
return EXIT_SUCCESS;
} |
Partager