Sat May 6 09:00:00 UTC 2023 inscode

上级 d7a0572c
class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
int[] arr = {4,2,3,10,23,1,43};
sort1(arr);
for (int i=0;i<arr.length;i++) {
System.out.println(arr[i]);
}
}
public static void sort1 (int[] arr) {
if (arr == null || arr.length == 1) {
return;
}
quickSort(arr, 0, arr.length -1);
}
public static void quickSort(int[] arr, int left, int right) {
if (left >= right) {
return;
}
int pivot = arr[left];
int i = left, j = right;
while (i < j) {
while (i < j && arr[j] >= pivot) {
j--;
}
if (i < j) {
arr[i++] = arr[j];
}
while (i < j && arr[i] < pivot) {
i++;
}
if (i < j) {
arr[j--] = arr[i];
}
}
arr[i] = pivot;
quickSort(arr, left, i - 1);
quickSort(arr, i + 1, right);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册