Java的快速排序代码
时间: 2023-03-14 10:32:22 浏览: 58
public static void quickSort(int[] arr, int start, int end) {
if (start < end) {
int partitionIndex = partition(arr, start, end);
quickSort(arr, start, partitionIndex-1);
quickSort(arr, partitionIndex+1, end);
}
}
private static int partition(int[] arr, int start, int end) {
int pivot = arr[end];
int i = start-1;
for (int j = start; j < end; j++) {
if (arr[j] <= pivot) {
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[i+1];
arr[i+1] = arr[end];
arr[end] = temp;
return i+1;
}
中文翻译:快速排序代码:
public static void quickSort(int [] arr,int start,int end){
if(start <end){
int partitionIndex = partition(arr,start,end);
quickSort(arr,start,partitionIndex-1);
quickSort(arr,partitionIndex + 1,end);
}
}
private static int partition(int [] arr,int start,int end){
int pivot = arr [end];
int i = start-1;
for(int j = start; j <end; j ++){
if(arr [j] <= pivot){
i ++;
int temp = arr [i];
arr [i] = arr [j];
arr [j] = temp;
}
}
int temp = arr [i + 1];
arr [i + 1] = arr [end];
arr [end] = temp;
return i + 1;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)