时间开销:O(logn),空间开销:0(原地分治)
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner scanner=new Scanner(System.in); System.out.println("数组长度:"); int n=scanner.nextInt(); int[] q=new int[n]; System.out.println("数组:"); for(int i=0;i<n;i++) { q[i]=scanner.nextInt(); } quickSort(q,0,n-1); System.out.print("排序后数组:"); for(int x:q){ System.out.print(x+" "); } } static void quickSort(int[] q,int l,int r) { if(l>=r) return; int i=l-1,j=r+1,m=q[l+r>>1]; while(i<j){ do i++; while(q[i]<m); do j--; while(q[j]>m); if(i<j) { int tmp=q[i]; q[i]=q[j]; q[j]=tmp; }; } quickSort(q,l,j);quickSort(q,j+1,r); } }
标签:scanner,int,out,System,new,排序,快速,Scanner From: https://www.cnblogs.com/lovxn/p/16989888.html