ma fonction ne trie pas le tableau
Bonjour,
j'ai fait un petit programme censé trier un tableau. Mais quand j'affiche le tableau après le tri, le tableau n'est pas trié ... Je suis un peu perdu. Voici mon code :
Code:
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 28 29 30 31
| #include <stdio.h>
#include <stdlib.h>
void sort(int* tab){
//int taille = sizeof(tab)/sizeof(int);
int taille = 10;
unsigned short int i, j, courant;
short int max;
i = 1;
for(courant=0; courant<taille; courant++){
max = tab[courant];
i = courant + 1;
while(max<tab[i] && i<taille){
max = tab[i];
i++;
}
tab[courant] = max;
}
for(j=0; j<10; j++){
printf("%d |", tab[j]);
}
printf("\n");
}
int main(){
int i;
int toto[10] = {9, 8, 3, 4, 7, 5, 1, 6, 2, 0};
sort(toto);
return 0;
} |
A l'execution ca me donne :
Code:
9 |8 |7 |7 |7 |5 |6 |6 |2 |0 |
Merci d'avance pour votre aide.