Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
if ( a.length <= 1 )
{
// Array of 1 element is sorted....
return;
}
/* ========================================================
Select the "pivot"
======================================================== */
pivot = a[a.length-1]; // Use last element as pivot
// This is the default choice...
/* ========================================================
Find out how many elements are <= and > than pivot
======================================================== */
nleft = nright = 0;
for ( i = 0; i < a.length-1; i++ )
{
if ( a[i] <= pivot ){
nleft++;
}
else{
nright++;
}
}
/* =================================================
Make the left and right array of the proper size
================================================= */
left = new double[nleft];
right = new double[nright];
/* =================================================
Partition array into 2 halves:
/* =================================================
Concatenate the pieces back
================================================= */
k = 0;
a[k++] = pivot;