改成java
时间: 2023-09-03 07:13:08 浏览: 69
Java解决AES加密解密 ( AES/ECB/PKCS5Padding )
以下是Java的代码实现:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
quickSort(arr, 0, n - 1);
}
public static void quickSort(int[] arr, int low, int high) {
if (low < high) {
int p = partition(arr, low, high);
for (int num : arr) {
System.out.print(num + " ");
}
System.out.println();
quickSort(arr, low, p - 1);
quickSort(arr, p + 1, high);
}
}
public static int partition(int[] arr, int low, int high) {
int pivot = arr[low];
int i = low, j = high;
while (i < j) {
while (i < j && arr[j] >= pivot) {
j--;
}
arr[i] = arr[j];
while (i < j && arr[i] <= pivot) {
i++;
}
arr[j] = arr[i];
}
arr[i] = pivot;
return i;
}
}
```
输入样例:
```
5
4 5 3 2 1
```
输出样例:
```
4 1 3 2 5
2 1 3 4 5
1 2 3 4 5
```
阅读全文