虽然C++中有sort可以用来排序,不过快排还是要会的;
#include <iostream>
#include <cstdio>
using namespace std;
void Qsort(int a[], int low, int high)
{
if(low >= high)
return ;
int i, j, k;
i = low;
j = high;
k = a[low];
while(low < high)
{
while(low < high && a[high] >= k)
high--;
a[low] = a[high];
while(low < high && a[low] <= k)
low++;
a[high] = a[low];
}
a[high] = k;
Qsort(a, i, high - 1);
Qsort(a, high + 1, j);
}
int main()
{
int a[1010];
for(int i = 0; i < 5; i++)
{
cin >> a[i];
}
Qsort(a, 0, 4);
for(int i = 0; i < 5; i++)
{
cout << a[i] << ' ';
}
return 0;
}