#include
#include
void quick_sort(int array[],int first, int last)
{
int temp, low, high, separator;
low = first;
high = last;
separator = array[(first + last) / 2];
do
{
while(array[low] < separator)
low++;
while(array[high] > separator)
high--;
if (low <= high)
{
temp = array[low];
array[low++] = array[high];
array[high--] = temp;
}
}while(low <= high);
if (first < high)
quick_sort(array, first, high);
if (low < last)
quick_sort(array, low, last);
}
int main(void)
{
int values[150], i;
for (i = 0; i < 150; i++)
values[i] = rand() % 1000;
quick_sort(values,0,149);
for (i = 0; i < 149; i++)
printf("%d ",values[i]);
return 0;
}
阅读(484) | 评论(0) | 转发(0) |