为什么分区方法的循环体从不抛出 ArrayIndexOutOfBounds 异常?
public static int partition( int[] a, low, high ) {
int k = low, m = low;
/* loop invariant:
* low <= k <= m <= high and
* all elements in a[low..k-1] are RED (i.e., < pivot) and
* all elements in a[k..m-1] are BLUE (i.e., >= pivot)
*/
while (m != high) {
if (a[m] >= pivot) // a[m] is BLUE
{ }
else { // a[m] is RED
swap(a,k,m);
k = k+1;
}
m = m+1;
}
return k;
}