int Sort(int a[],int low,int high)
{
int mid_axis=a[low]; //中轴的值
while(low<high)
{
while(low<high&&a[high]>=mid_axis)
{
high--;
}
a[low]=a[high];
while(low<high&&a[low]<=mid_axis)
{
low++;
}
a[high]=a[low];
}
a[low]=mid_axis;
return low;
}
void QuickSort(int a[],int low,int high)
{
if (high<=low)
{
return;
}
int axis=Sort(a,low,high);
QuickSort(a,low,axis-1);
QuickSort(a,axis+1,high);
}
int main()
{
int a[16]={33,1,5,7,2,4,9,6,33,1,5,7,2,4,9,6};
QuickSort(a,0,15);
for (int i=0;i<16;i++)
{
cout<<a[i]<<" ";
}
system("pause");
return 0;
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布