1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
void quickSort(int numbers[],int array_size)
{
q_sort(numbers, 0, array_size - 1);
}
void q_sort(int numbers[], int left, int right)
{
int q;
if (left < right) {
q = partition(numbers, left, right);
q_sort(numbers,left, q);
q_sort(numbers, q+1, right);
}
}
int partition(int numbers[], int left, int right)
{
int x = numbers[left], i = left-1, j = right + 1, temp;
bool again = true;
while (again){
do {} while (numbers[++i] < x);
do {} while (numbers[--j] > x);
if (i < j) {
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
else again = false;
}
return j;
}
|