import java.util.Arrays;
public class quickSort {
public static void main(String[] args) {
int k [] ={12,4,5,9,78,72,1923};
int low =0;
int height=5;
quickSort(k, low, height);
System.out.println(Arrays.toString(k));
}
public static int partition(int k[],int low ,int height){
int point = k[low];
while(low<height){
while(low<height && k[height]>=point){
height--;
}
swap(k,low,height);
while(low<height && k[low]<=point){
low++;
}
swap(k,low,height);
}
return low;
}
public static void swap(int[] k, int low, int height) {
int temp = k[low];
k[low]=k[height];
k[height]=temp;
}
public static void quickSort(int k[],int low,int height){
if(low<height){
int point = partition(k, low, height);
quickSort(k, low, point-1);
quickSort(k, point+1, height);
}
}
public class quickSort {
public static void main(String[] args) {
int k [] ={12,4,5,9,78,72,1923};
int low =0;
int height=5;
quickSort(k, low, height);
System.out.println(Arrays.toString(k));
}
public static int partition(int k[],int low ,int height){
int point = k[low];
while(low<height){
while(low<height && k[height]>=point){
height--;
}
swap(k,low,height);
while(low<height && k[low]<=point){
low++;
}
swap(k,low,height);
}
return low;
}
public static void swap(int[] k, int low, int height) {
int temp = k[low];
k[low]=k[height];
k[height]=temp;
}
public static void quickSort(int k[],int low,int height){
while(low<height){
int point = partition(k, low, height);
}
public class quickSort {
public static void main(String[] args) {
int k [] ={12,4,5,9,78,72,1923};
int low =0;
int height=5;
quickSort(k, low, height);
System.out.println(Arrays.toString(k));
}
public static int partition(int k[],int low ,int height){
int point = k[low];
while(low<height){
while(low<height && k[height]>=point){
height--;
}
swap(k,low,height);
while(low<height && k[low]<=point){
low++;
}
swap(k,low,height);
}
return low;
}
public static void swap(int[] k, int low, int height) {
int temp = k[low];
k[low]=k[height];
k[height]=temp;
}
public static void quickSort(int k[],int low,int height){
if(low<height){
int point = partition(k, low, height);
quickSort(k, low, point-1);
quickSort(k, point+1, height);
}
}
}
#递归优化版
import java.util.Arrays;public class quickSort {
public static void main(String[] args) {
int k [] ={12,4,5,9,78,72,1923};
int low =0;
int height=5;
quickSort(k, low, height);
System.out.println(Arrays.toString(k));
}
public static int partition(int k[],int low ,int height){
int point = k[low];
while(low<height){
while(low<height && k[height]>=point){
height--;
}
swap(k,low,height);
while(low<height && k[low]<=point){
low++;
}
swap(k,low,height);
}
return low;
}
public static void swap(int[] k, int low, int height) {
int temp = k[low];
k[low]=k[height];
k[height]=temp;
}
public static void quickSort(int k[],int low,int height){
while(low<height){
int point = partition(k, low, height);
quickSort(k, low, point-1);
low = point+1;
}}
}