#include<iostream>
#include<math.h>
using namespace std;
void quick_sort(int s[], int l, int r)
{
if (l > r)
return;
int i = l, j = r, x = s[l];
while (i < j)
{
while (i < j&&s[j] >= x)
j--;
if (i < j)
s[i++] = s[j];
while (i < j&&s[i] < x)
i++;
if (i < j)
s[j--] = s[i];
}
s[i] = x;
quick_sort(s, l, i - 1);
quick_sort(s, i + 1, r);
}
int main()
{
int a[] = { 4,3,54,2,554,6 };
quick_sort(a, 0, 5);
for (int i=0;i<6;i++)
{
cout << a[i]<<" ";
}
system("pause");
}
网友评论