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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <stdio.h>
// Fonctions
unsigned int position_of_min(char tableau[], unsigned int length, unsigned int position)
{
unsigned int tpos=position;
for( ; position<length; position++)
{
if(tableau[position] < tableau[tpos])
{
tpos=position;
}
}
return tpos;
}
void recursive_sort(char (*tableau)[], unsigned int length)
{
// Recuperation du min
unsigned int mpos = position_of_min( (*tableau), length, 0 );
char min = (*tableau)[mpos];
// Echange
(*tableau)[mpos] = (*tableau)[0];
(*tableau)[0] = min;
// Trier le reste du tableau
if(length>=3)
recursive_sort( (*tableau+1), length-1 );
}
void display_tableau(char tableau[], unsigned int length)
{
unsigned int i=0;
for(printf("|"), i=0; i<length; printf(" %4d |", tableau[i++]))
;
printf("\n\n");
}
// Main
int main(void)
{
char tab[]={100,90,15,78,9,-66,5,10,94};
unsigned int len = sizeof(tab)/sizeof(tab[0]);
display_tableau(tab, len);
recursive_sort(tab, len);
//recursive_sort(&tab, len);
display_tableau(tab, len);
return 0;
} |