/**
* @author paidaxing
* @date 2021/8/25
*/
public class QuickSort1 {
public static void quickSort(int arr[],int low,int high){
int i,j,temp;
if(low > high){
return;
}
i = low;
j = high;
temp = arr[low];
while (i < j){
while (temp<=arr[j]&&i<j){
j--;
}
while (temp>=arr[i]&&i<j){
i++;
}
if(i < j){
int a = arr[i];
int b = arr[j];
arr[j] = a;
arr[i] = b;
}
}
arr[low] = arr[i];
arr[i] = temp;
//递归调用左半数组
quickSort(arr,low,i-1);
//递归调用右半数组
quickSort(arr,i+1, high);
}
public static void main(String[] args) {
int[] arr = {1,9,6,5,3,4,5,10};
quickSort(arr,0, arr.length-1);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
快速排序----java实现
最新推荐文章于 2024-09-29 09:19:41 发布