|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
using namespace std;
int Partition(int a[], int low, int high)
{
int pivotkey;
a[0] = a[low];
pivotkey = a[low];
while (low < high) {
while (low < high && a[high] >= pivotkey)--high;
a[low] = a[high];
while (low < high && a[low] <= pivotkey)++low;
a[high] = a[low];
}
a[low] = a[0];
return low;
}
void quicksort(int a[], int low, int high) {
if (low < high) {
int pivotloc = Partition(a, low, high);
quicksort(a, low, pivotloc - 1);
quicksort(a, pivotloc + 1, high);
}
}
int main()
{
int n, a[1000001], a1 = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
quicksort(a, a1, n );
for (int i = 1; i <= n; i++)
cout << a[i]<<" ";
return 0;
} |
|