/*
3.快速排序(东软喜欢考类似的算法填空题,又如堆排序的算法等)
*/
int Parition(int *p,int low,int high)
{
int pivotkey=p[low];
while(low<high)
{
while((low<high)&&(p[high]>=pivotkey))//这里相等不能丢掉
high--;
p[low]=p[high];
while((low<high)&&(p[low]<=pivotkey))
low++;
p[high]=p[low];
}
p[low]=pivotkey;
return low;
}
void QuickSort(int *p,int low,int high)
{
if(low>=high)
return;
int pivot=Parition(p,low,high);
QuickSort(p,low,pivot-1);
QuickSort(p,pivot+1,high);
}
void QuickSortTest()
{
int p[]={10,0,15,12,-10,-5,9,2,8,6,4,20,19,6,8,7};
int len=sizeof(p)/sizeof(int);
cout<<"the array : ";
ShowArray(p,len);
cout<<"after sort : ";
QuickSort(p,0,len-1);
ShowArray(p,len);
}