从头遍历的快速排序
#include<iostream>
#include <string>
#include <stack>
#include <deque>
using namespace std;
int partition2(int * p,int low,int high)
{
int t=p[low];
int a=low+1,b=low+1;
//一个人蹲点 一个人去遍历
while(b<=high)
{
while(b<=high && p[b]>=t)
b++;
if(b<=high)
{
swap(p[a],p[b]);
b++;
a++;
}
}
p[low]=p[a-1];
p[a-1]=t;
return a-1;
}
void quick(int a[],int l,int r)
{
if(l<r)
{
int i=partition2(a,l,r);
quick(a,l,i-1);
quick(a,i+1,r);
}
}
void main()
{
int a[]={5,7,3,9,1,8,12,4};
quick(a,0,7);
cout<<"---------------------------------"<<endl;
for(int i=0;i<8;i++)
cout<<a[i]<<endl;
}