学习 算法导论上的
感觉比我自己写的好多了 呵呵
#include <iostream>
#include <cmath>
using namespace std;
int Quicksort(int *a,int low,int high)
{
int x = a[high];
int i = low - 1;
for(; low < high; low++)
{
if(a[low] <= x)
{
i++;
swap(a[i],a[low]);
}
}
swap(a[i+1],a[high]);
return i+1;
}
void Partition(int *a,int low,int high)
{
if(low < high)
{
int mid = Quicksort(a,low,high);
Partition(a,low,mid-1);
Partition(a,mid+1,high);
}
}
int main()
{
int a[200];
int n,i;
cin>>n;
for(i = 1; i <= n; i++)cin>>a[i];
Partition(a,1,n);
for(i = 1; i <= n; i++)cout<<a[i]<<" ";
cout<<endl;
return 0;
}