/*这个快速排序算法在轴的选取上采用它以最右边的值s作比较的标准,将整个数列分为三个部份,
一个是小于s的部份,一个是大于s的部份,一个是未处理的部份*/
#include <iostream>
#include <stdlib.h>
using namespace std;
#define swap(x,y){int t = x; x = y; y = t;}
void fast_shot(int a[],int begin,int end)
{
int i=0,j=0;
if (begin<end)
{
while (i<end)
{
if (a[i] < a[end])
{
swap(a[i],a[j]);
j++;
}
i++;
}
swap(a[j],a[end]);
fast_shot(a,begin,j-1);
fast_shot(a,j+1,end);
}
}
int main()
{
int a[]={11, 25, 11, 4, 88, 2, 108, 3, 2, 21};
fast_shot(a,0,9);
for (int i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
system("pause");
}
快速排序法(三)
最新推荐文章于 2023-03-30 15:33:35 发布