#include <stdio.h>
void quick_sort(int carry[], int left, int right);
void quick_sort(int carry[], int left, int right)
{
int i, j, middle, temp;
middle = carry[(left + right) / 2];
i = left;
j = right;
while(i <= j)
{
while(carry[i] < middle)
{
i++;
}
while(carry[j] > middle)
{
j--;
}
//if(i < j)
if(i <= j)
{
temp = carry[j];
carry[j] = carry[i];
carry[i] = temp;
i++;
j--;
}
}
if(left < j)
{
quick_sort(carry, left, j);
}
if(i < right)
{
quick_sort(carry, i, right);
}
}
int main()
{
int carry[] = {1, 2, 34, 46, 356, 11, 567, 65, 234, 64, 123, 64, 22,78};
int i;
int length = (sizeof(carry) / sizeof(carry[0]));
quick_sort(carry, 0, length - 1);
for(i = 0; i < length; i++)
{
printf("%d ", carry[i]);
}
putchar('\n');
return 0;
}
|