将y总模板do-while改为while版本(Java)
import java.util.Scanner;
import java.io.BufferedInputStream;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
quick_sort(arr, 0, n - 1);
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
private static void quick_sort(int[] nums, int l, int r)
{
if (l >= r) return;
int i = l, j = r, x = nums[l + r >> 1];
while (true)
{
while (nums[i] < x) {
i++;
}
while (nums[j] > x) {
j--;
}
if (i < j) {
swap(nums, i++, j--);
} else {
break;
}
}
quick_sort(nums, l, j);
quick_sort(nums, j + 1, r);
}
private static void swap(int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}