#include
#define N 8
void quicksort(int s[], int low, int high)
{
int key, i = low, j = high;
key = s[i];
while (i < j)
{
while ((i < j) && (s[j] >= key)) j--;
if (i < j) s[i] = s[j];
while ((i < j) && (s[i] <= key)) i++;
if (i < j) s[j] = s[i];
}
s[i] = key;
if (i-1 > low) quicksort(s, low, i-1);
if (i+1 < high) quicksort(s, i+1, high);
return ;
}
int main()
{
int i, s[N] = {23, 6, 15, 27, 19, 30, 42, 20};
quicksort(s, 0, N-1);
for (i=0; i {
printf("%d ", s[i]);
}
printf("\n");
return 0;
}
阅读(906) | 评论(0) | 转发(1) |