
public class QuickSort {
public static void quickSort(int arr[],int _left,int _right){
int left = _left;
int right = _right;
int temp = 0;
if(left <= right){
temp = arr[left];
while(left != right){
while(right > left && arr[right] >= temp)
right --;
arr[left] = arr[right];
while(left < right && arr[left] <= temp)
left ++;
arr[right] = arr[left];
}
arr[right] = temp;
quickSort(arr,_left,left-1);
quickSort(arr, right+1,_right);
}
}
public static void main(String[] args) {
int array[] = {10,5,3,1,7,2,8};
System.out.println("排序之前:");
for(int element : array){
System.out.print(element+" ");
}
quickSort(array,0,array.length-1);
System.out.println("\n排序之后:");
for(int element : array){
System.out.print(element+" ");
}
}
}
package com.edu.shengda.suanfa;
public class 快排 {
public static void quickSort(int[] arr,int low,int high) {
int i,j,temp,t;
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){
t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
arr[low]=arr[i];
arr[i] = temp;
quickSort(arr, low, j-1);
quickSort(arr, j+1, high);
}
public static void main(String[] args){
int[] arr = {10,7,2,4,7,62,3,4,2,1,8,9,19};
quickSort(arr, 0, arr.length-1);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}