#include <iostream>
using std::cin;
using std::cout;
void Swap(int &a, int &b)
{
//a = a + b;
//b = a - b;
//a = a - b;
if (a != b){
a ^= b;
b ^= a;
a ^= b;
}
}
int Sort(int *Arry, int start, int end)
{
int Swap_pos = start;
for (int i = start; i <= end; ++i){
if (Arry[i] < Arry[end]){
Swap(Arry[i], Arry[Swap_pos]);
Swap_pos++;
}
}
Swap(Arry[Swap_pos], Arry[end]);
return Swap_pos;
}
void QuickSort(int *Arry, int start, int end)
{
if (start < end) {
int p = Sort(Arry, start, end);
QuickSort(Arry, start, p - 1);
QuickSort(Arry, p + 1, end);
}
}
int main(void)
{
int n = 0;
while (cin >> n){
if (n <= 0) break;
int *Arry = new int[n];
for (int i = 0; i < n; ++i)
cin >> Arry[i];
QuickSort(Arry, 0, n - 1);
for (int i = 0; i < n; ++i)
cout << Arry[i] << ' ';
cout << "\n";
delete []Arry;
}
return 0;
}
QuickSort
最新推荐文章于 2024-05-14 10:51:55 发布