public class kuaisupaixu {
public static void quicksort(int[] a,int lo,int hi){
if(lo<hi){
int i=lo,j=hi;
int x=a[lo];
while(i<j){
while(i<j&&a[j]>=x)
j--;
if(i<j)
a[i++]=a[j];
while(i<j&&a[i]<x)
i++;
if(i<j)
a[j--]=a[i];}
a[i]=x;
quicksort(a,lo,i-1);
quicksort(a,i+1,hi);
}
}
public static void main(String[] args){
int[] array=new int[]{19,5,4,16,3,78,24,1};
System.out.println("排序前的数组为:");
for(int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
System.out.println();
quicksort(array,0,array.length-1);
System.out.println("排序后的数组为:");
for( int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
}}
public static void quicksort(int[] a,int lo,int hi){
if(lo<hi){
int i=lo,j=hi;
int x=a[lo];
while(i<j){
while(i<j&&a[j]>=x)
j--;
if(i<j)
a[i++]=a[j];
while(i<j&&a[i]<x)
i++;
if(i<j)
a[j--]=a[i];}
a[i]=x;
quicksort(a,lo,i-1);
quicksort(a,i+1,hi);
}
}
public static void main(String[] args){
int[] array=new int[]{19,5,4,16,3,78,24,1};
System.out.println("排序前的数组为:");
for(int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
System.out.println();
quicksort(array,0,array.length-1);
System.out.println("排序后的数组为:");
for( int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
}}