快速排序c++实现
//2010/12/21 20:37:26 //快速排序 #include <iostream> using namespace std; void sort(int array[],int zz,int yy) { int z,y,i,k; if(zz<yy) { z=zz; y=yy; k=array[z]; do { while((z<y)&&(array[y]>=k)) y--; if(z<y) //右边的元素小于k,移到k左 { array[z]=array[y]; z=z+1; } while((z<y)&&(array[z])<=k) z++; if(z<y) //左边的元素大于k,移动右边 { array[y]=array[z]; } } while(z!=y); array[z]=k; for(i=zz;i<=yy;i++) { cout<<"a["<<i<<"]="<<array[i]<<";"; } cout<<endl; sort(array,zz,z-1); sort(array,z+1,yy); } } int main() { int a[10],i; cout<<"请输入10个数"<<endl; for(i=0;i<10;i++) { cin>>a[i]; } sort(a,0,9); cout<<"排序结果为"; for (i=0;i<10;i++) cout<<a[i]<<";"; cout<<endl; return 0; }