快速排序
注意一下: 必须要用key存下num[(l+r)>>1]的值,因为在里面会变动
import java.math.*; import java.util.*; public class Main { public static HashMap<String,Long> map = new HashMap<>(); public static void main(String args[]) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int fx[] = new int[n]; int N=n,x; for(int i=0;i<n;i++) { fx[i] = input.nextInt(); } QuickSort(fx,0,fx.length-1); for(int i=0;i<n;i++) System.out.print(fx[i]+" "); } public static void QuickSort(int num[],int l, int r) { int key = num[(l+r)>>1],i=l,j=r,temp=0; while(i<=j){ while(num[i]<key) i++; while(num[j]>key) j--; if(i<=j) { temp = num[i]; num[i] = num[j]; num[j] = temp; i++; j--; } } if(i<r) QuickSort(num,i,r); if(j>l) QuickSort(num,l,j); } }