思路:先请出来一个,然后一个个比,递归
public class QuickSort {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {10,15,5,67,3,18,20};
QuickSort qs = new QuickSort();
qs.quickSort(a, 0, a.length-1);
for(int i = 0;i<a.length;i++){
System.out.println(a[i]);
}
}
public void quickSort(int[] a,int low,int high)
{
int mid;
if(low<high)
{
mid = partition(a,low,high);
quickSort(a,low,mid-1);
quickSort(a,mid+1,high);
}
}
//this time I forgot three equals;
private int partition(int[] a, int low, int high) {
// TODO Auto-generated method stub
int pivot = a[low];
while(low<high)
{
while(low<high && a[high]>=pivot)
high--;
a[low] = a[high];
while(low<high && a[low]<=pivot)
low++;
a[high] = a[low];
}
a[low] = pivot;
return low;
}
}