int Partition(double *Array,int left,int right)
{
double pivot=Array[left];
int i=left;
double tmp;
for (int j=left+1;j<=right;j++)
{
if (Array[j]<=pivot)
{
i++;
tmp=Array[j];
Array[j]=Array[i];
Array[i]=tmp;
}
}
//exchange A[i],pivot
tmp=Array[left];
Array[left]=Array[i];
Array[i]=tmp;
return i;
}
void QuickSort(double *Array,int left,int right)
{
if (left>=right)
{
return;
}
int p=Partition(Array,left,right);
QuickSort(Array,left,p-1);
QuickSort(Array,p+1,right);
}
void main()
{
double A[]={8,4,3,2,6,13,5};
int n=7;
//MergeSort(&A[0],0,6);
QuickSort(A,0,6);
for (int i=0;i<n;i++)
{
cout<<A[i]<<" ";
}
cout<<endl;
delete A;
}
Homepage:
http://www.zoumin.org/