package A;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
public class JosePhu {
public static void main(String[] args) {
Method method=new Method();
//int[] a={5,9,4,2,1,10,7,8,3,6};
int[] a={-9,78,0,0,23,-567,70};
//left=0,是代表数组下标是从0开始的(即最左端),而不是a数组里的0
method.quickSort(a,0,a.length-1);
System.out.println(Arrays.toString(a));
}
}
package A;
import java.util.Arrays;
public class Method {
public void quickSort(int[] a,int L,int R){
int left=L;
int right=R;
int temp=0;
int pivot=a[(left+right)/2];
while (left<right){
while (a[left]<pivot){
left++;
}
while (a[right]>pivot){
right--;
}
if (left==right){
break;
}
temp=a[left];
a[left]=a[right];
a[right]=temp;
if (a[left]==pivot){
right--;
}
if (a[right]==pivot){
left++;
}
}
if (left==right){
left++;
right--;
}
if (L<right){
quickSort(a,L,right);
}
if (R>left){
quickSort(a,left,R);
}
}
}