java的快速排序怎么写?
时间: 2023-03-10 19:03:23 浏览: 59
在Java中,可以使用以下代码实现快速排序:
public static void quickSort(int[] arr,int start,int end){
int pivot = arr[start];
int i = start;
int j = end;
while(i<j){
while((i<j)&&(arr[j]>pivot)){
j--;
}
while((i<j)&&(arr[i]<pivot)){
i++;
}
if((arr[i]==arr[j])&&(i<j)){
i++;
}else{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
if(i-1>start) quickSort(arr,start,i-1);
if(j+1<end) quickSort(arr,j+1,end);
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![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_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)