quicksort
Una implementación simple en C.
<pre>
void quicksort(int * low, int * high)
{
/* We naively use the first value in the array as the pivot */
/* this will not give good performance real usage */
int * lowbound = low + 1; /* the high boundary of the low subarray */
int * highbound = high - 1; /* the low boundary of the high subarray */
int temp;
while(lowbound <= highbound) /* partition the array */
{
if(*lowbound < *low) /* compare to pivot */
lowbound++; /* move lowbound toward the middle */
else
{
temp = *lowbound; /* swap *lowbound and *highbound */
*lowbound = *highbound;
*highbound = temp;
highbound--; /* move highbound toward the middle */
}
}
highbound++; /* move bounds back to the correct positions */
lowbound--;
temp = *low; /* move the pivot into the middle */
*low = *lowbound;
*lowbound = temp;
if(low != lowbound) /* recurse on the subarrays */
quicksort(low, lowbound);
if(high != highbound)
quicksort(highbound, high);
}
<pre>
- Hoare, Charles Anthony R.Sri Lanka, 1934 -
- sortclasificar, ordenar
- sorting algorithmalgoritmo de clasificación