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
| void tri(nb)
{
tri_bis(0,nb-1);
}
void tri_bis(int debut, int fin)
{
int pivot;
if (debut < fin)
{
pivot = placement_pivot(debut, fin);
tri_bis (debut, pivot-1);
tri_bis (pivot+1, fin);
}
}
int placement_pivot(int debut, int fin)
{
int compteur = debut;
int pivot = table[debut];
int i;//indice
for (i=debut+1; i<=fin; i++)
{
if (strcmp (table[i], table[pivot]) < 0)//test de la valeur de ligne
{
pivot=i;
strcpy (buf, table[compteur] );//echange des indices
strcpy (table[compteur], table[pivot]);
strcpy (table[pivot], buf);
}
strcpy (buf, table[debut] );//echange des indices
strcpy (table[compteur], table[debut]);
strcpy (table[compteur], buf);
return(compteur);
}
} |
Partager