谢谢y老师模版和大佬们题解❤️
年轻y总好帅爱了爱了❤️
有输入输出版😄
java:
import java.util.*;
public class Main{
private static int N = 100010;
private static int[] q = new int[N];
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for(int i = 0; i <n; i++){
q[i] = scanner.nextInt();
}
int l = 0, r = n - 1;
quicksort(q, l, r);
for(int i = 0; i < n; i++){
System.out.print(q[i] + " ");
}
}
public static void quicksort(int[] q, int l, int r){
if (l >= r){
return;
}
int x = q[l + r >> 1];
int i = l - 1;
int j = r + 1;
while(i < j){
do i ++; while (q[i] < x);
do j --; while (q[j] > x);
if(i < j){
int tmp = q[i];
q[i] = q[j];
q[j] = tmp;
}
}
quicksort(q, l ,j);
quicksort(q, j + 1, r);
}
}