单向扫描
基准数为最右边
private static void quickSortLineryArray(int[] a, int start, int end) {
if(a.length == 0 || a.length == 1) {
return ;
}
int i = start;
int j = start; //j负责检查小于key的
int key = a[end];
while(j < end){
if(a[j] < key) {
//每查到一个和i交换位置,i之前的位置都小于key
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
}
j++;
}
int tmp = a[i];
a[i] = a[end];
a[end] = tmp;
if(i > start)quickSortLineryArray(a, start, i-1);
if(i < end)quickSortLineryArray(a, i+1, end);
}
双向扫描
基准数为最左边(就要右边指针先动),基准数