#include <iostream>
using namespace std;
int a[50];
int Partion(int begin, int end)
{
int compare=a[begin], left =begin,right = end;
if(left >right)
return -1;
while (left <right)
{
while ((left <right) && a[right]>=compare)
right--;
a[left++] = a[right];
while ((left <right) &&(a[left] <compare))
left++;
a[right--] = a[left];
}
a[left] = compare;
return left;
}
void qs(int begin,int end)
{
if (begin < end)
{
int split = Partion(begin, end);
qs(begin,split-1);
qs(split+1,end);
}
}
int main()
{
int i;
for (i =0; i< 50; i++)
{
a[i] =50-i;
}
cout<<"排序前"<<endl;
for (i= 0; i<50; i++)
{
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}
cout<<"排序后"<<endl;
qs(0,49);
for (i=0; i<50; i++)
{
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}
return 0;
}