//快速排序
//***************************************************************************//
//2011.09.28
//快速排序递归算法
#include<iostream.h>
#include<stdlib.h>
int Slipt(int a[], int low, int high);
void QuickSort(int a[], int low, int high);
const int num=10;
void main()
{
int a[num];
int i;
for(i=0; i<num; i++)
{
a[i]=rand()0;
cout<<a[i]<<" ";
}
cout<<endl;
QuickSort(a,0,num);
for(i=0; i<num; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
void QuickSort(int a[], int low, int high)
{
int i;
if(low<high)
{
i=Slipt(a,low,high);
QuickSort(a,low,i);
QuickSort(a,i+1,high);
}
}
int Slipt(int a[], int low, int high)
{
int i,j,x,temp;
x=a[low];
i=low;
for(j=low; j<high; j++)
{
if(a[j]<x)
{
i=i+1;
if(i!=j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
temp=a[low];
a[low]=a[i];
a[i]=temp;
return i;
}