public class QuickSort {
public static void main(String[] args) {
int [] arr = new int [] {3,2,5,8,4,7,6,9,1,0};
quickSort(arr,0,arr.length-1);
for (int i = 0;i < arr.length;i++) {
System.out.print(arr[i]+" ");
}
}
public static void quickSort(int [] arr ,int left ,int right){
if(left >= right) {
return;
}
int start = left;
int end = right;
int p=arr[left];
while(left<right) {
while(left < right && arr[right] >= p) {
right--;
}
if(right > left) {
arr[left]=arr[right];
}
while(left < right && arr[left] <= p) {
left++;
}
if(right > left) {
arr[right]=arr[left];
}
}
arr[right]=p;
quickSort(arr, start, right-1);
quickSort(arr, right+1, end);
}
}
CRUD_BOY。
发布了19 篇原创文章 · 获赞 3 · 访问量 3645
私信
关注