top of page
Tri rapide
function quick_sort(tab, g0, d0) {
if (g0 >= d0) {
return;
}
g = g0;
d = d0;
p = tab[g];
while(g < d){
if(tab[g + 1] < p){
tab[g] = tab[g + 1];
g++;
} else {
a = tab[d];
tab[d] = tab[g + 1];
tab[g + 1] = a;
d--;
}
}
tab[d] = p;
quick_sort(tab, g0, d - 1);
quick_sort(tab, g + 1, d0);
}
tab = [15,7,9,18,17,3,19,20,14,11];
quick_sort(tab, 0, tab.length -1);
print(tab);
bottom of page