快速排序
public class quickSort { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(); int n=sc.nextInt(); int[] arr=new int[n+1]; for(int i=0;i<=n;i++){ arr[i]=sc.nextInt(); } // int[] arr={5,1,4,2,3}; quickSort(arr,0,n); for(int i=0;i<arr.length;i++){ System.out.print(arr[i]+" "); } } public static void quickSort(int arr[],int m,int n){ if(arr.length==1||m>n) return ; int temp=arr[m]; int l=m; int r=n; while(l!=r){ while(temp<=arr[r]&&l<r) r--; while(temp>=arr[l]&&l<r) l++; if(l<r){ int t=arr[l]; arr[l]=arr[r]; arr[r]=t; } } arr[m]=arr[l]; arr[l]=temp; quickSort(arr,m,r-1); quickSort(arr,l+1,n); } }