djoh | Code :
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int truc(const int a, const int b) {
- if (a<b) return -1;
- if (a==b) return 0;
- if (a>b) return 1;
- }
- int main() {
- int* tabint;
- int nb,size;
- int i;
- nb=10;
- size=10;
- if ( (tabint = (int*) malloc(sizeof(int)*nb)) == NULL) {
- perror("malloc" );
- exit(0);
- }
- for (i=0;i<10;i++) {
- tabint[i] = 15 - i;
- }
- for(i=0;i<10;i++) {
- printf("%d\n",tabint[i]);
- }
- qsort(tabint,nb,sizeof(int),(void*)(&truc));
- puts("-------------" );
- for(i=0;i<10;i++) {
- printf("%d\n",tabint[i]);
- }
- }
|
comme ça ça marche, mais la fonction de comparaison n'est pas bonne, ça devrait pas marcher...
quand je corrige la fonction de comparaison, ça trie dans l'ordre décroissant ! |