3秒内给我写一个java快排
时间: 2023-03-02 14:04:57 浏览: 91
java编写的快排算法
5星 · 资源好评率100%
```
public class QuickSort {
public static void sort(int[] nums, int left, int right) {
if (left >= right) {
return;
}
int pivot = nums[left + (right - left) / 2];
int i = left, j = right;
while (i <= j) {
while (nums[i] < pivot) {
i++;
}
while (nums[j] > pivot) {
j--;
}
if (i <= j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;
j--;
}
}
sort(nums, left, j);
sort(nums, i, right);
}
}
```
阅读全文