#include<iostream>
using namespace std;
void QuickSort(int a[],int low,int high)
{
if(low < high)
{
int pivot = a[low]; //基准
int first = low;
int last = high;
while(first < last)
{
while(first < last && a[last] > pivot)
{
--last;
}
a[first] = a[last]; //将小的移到低端
while(first < last && a[first] <= pivot)
{
++first;
}
a[last] = a[first]; //将大的移到高端
}
a[first] = pivot;
QuickSort(a,low,first-1);
QuickSort(a,first+1,high);
}
else
{
return;
}
}
void main()
{
int a[] = {57,68,59,52,72,28,96,33,24};
int count = sizeof(a) / sizeof(a[0]);
QuickSort(a,0,count-1);
for(int i=0;i<count;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
[Sort]快速排序-递归实现
最新推荐文章于 2022-03-16 11:01:44 发布