30.03.2015, 02:15
pawn Код:
stock quickSort(array[], left, right)
{
/*new
array[] = { -541, 54, 689, 12, 3, 0, 3, 55, 66, -541, 5468484, -564, 1554, 1656 }
;
quickSort(array, 0, sizeof(array) - 1);
for(new i; i != sizeof(array); ++i)
{
printf("%d", array[i]);
}*/
new templeft = left, tempright = right, pivot = array[(left + right) / 2], tempvar;
while(templeft <= tempright)
{
while(array[templeft] < pivot) templeft ++;
while(array[tempright] > pivot) tempright --;
if(templeft <= tempright)
{
tempvar = array[templeft], array[templeft] = array[tempright], array[tempright] = tempvar;
templeft ++, tempright --;
}
}
if(left < tempright) quickSort(array, left, tempright);
if(templeft < right) quickSort(array, templeft, right);
}