快排
思路:以end为对象,进行比较,小的放左边,大的放右边,然后用递归
#include<stdio.h> int nice(int m[],int left,int right){ int j=left-1,temp; for(int i=left;i<=right;++i){ if(m[i]<=m[right])j++,temp=m[j],m[j]=m[i],m[i]=temp; } return j; } int quiksort(int m[],int left,int right){int middle; if(left<right){ middle=nice(m,left,right); quiksort(m,left,middle-1); quiksort(m,middle+1,right); } } int main(){ int n,m[100010]; while(~scanf("%d",&n)){ for(int i=0;i<n;++i)scanf("%d",m+i); quiksort(m,0,n-1); for(int i=0;i<n;++i){ if(i)printf(" "); printf("%d",m[i]); } } return 0; }