void tri_bulle(int tab[], int bi ,int bs)
{
int ic = bs-1, idp=ic, temp;
while (ic>= bi)
{
while ((ic<bs) && (tb[ic]>tb[ic+1]))
{
temp = tab[ic+1];
tab[ic+1] = tab[ic];
tab[ic] = temp;
ic++;
}
idp--;
ic=idp;
}
}
ou
void tri_bulle2(int t[], int bi, int bs)
{
int ib, ic, idp, x;
for (ib=bi ; ib<bs; )
{
for (ic=bs, idp=bs ; ic>ib ; ic--)
if (t[ic]<t[ic-1])
{
x= t[ic];
t[ic]= t[ic-1];
t[ic-1]= x;
idp= ic;
}
ib= idp;
}
}
le plus rapide :
void tri_rapide(int tab[], int bi, int bs)
{
int x= tab[(bi+bs)/2], sav, g= bi, d= bs;
do
{
while (tab[g]<x) g++;
while (tab[d]>x) d--;
if (g<=d) {
sav = tab[g];
tab[g]= tab[d];
tab[d] = sav;
g++; d--;
}
} while (g<=d);
if (bi<d) tri_rapide(tab,bi,d);
if (g<bs) tri_rapide(tab,g,bs);
}