我的交换比你少一半..
#include <iostream>
#define SWAP(a,b) {int c=a;a=b;b=c;}
using namespace std;
const int N=11;
int Mv[N]={12,34,1,1,10,8,5,101,15,9,58};
int Partition(int iLow,int iHigh){
int iKey=Mv[iLow];
int j=iLow;
while(1)
{
while(Mv[iLow]<=iKey&&iLow<=iHigh) iLow++;
while(Mv[iHigh]>iKey&&iLow<=iHigh) iHigh--;
if(iLow<iHigh)
{SWAP(Mv[iLow],Mv[iHigh])}
else
break;
}
SWAP(Mv[j],Mv[iLow-1])
return iLow-1;
}
void QuickSort(int iLow,int iHigh){ //[0-(n-1)]
if(iLow<iHigh)
{
int p=Partition(iLow,iHigh);
QuickSort(iLow,p-1);
QuickSort(p+1,iHigh);
}
}
void ShowMv(){
int i;
for(i=0;i<N-1;++i)
cout<<Mv[i]<<" ";
cout<<Mv[i];
}
int main(){
QuickSort(0,N-1);
ShowMv();
return 0;
}