//把最后一个当主元 piovt
int small = s;
int pivot = a[e];
int i = s, j = e ;
while( i < j){
if(a[i] >= pivot){
i++;
}else{
swap(a[small],a[i]);
i++;
++small;
}
}
swap(a[small],a[e]);
return small;
int temp = a[s];
int i = s, j = e;
while(i < j ){
while(a[j]>= temp && i < j){
j--;
}
if(i<j)
a[i++] = a[j];
while(a[i]<temp && i < j){
i++;
}
if(i<j)
a[j--] = a[i];
}
a[i] = temp;
return i;
快排的多重实现方式
#include <iostream>
using namespace std;
/*快排*/
int quick(int a[], int s, int e)
{
//上面两种都可以.
}
void quicksort(int a[], int s, int e)
{
if(s < e)
{
int i = quick(a,s,e);
quicksort(a,s,i-1);
quicksort(a,i+1,e);
}
}
int main()
{
int a[] = {-4,45,54,23,432,45,65,1}; // 8 elements;
int s = 0, e = 7;
quicksort(a,s,e);
for( int i = 0 ;i <= e;i++)
cout<<a[i]<<" ";
cout<<endl;
}